proxygen
folly::coro Namespace Reference

Namespaces

 detail
 

Classes

struct  await_result
 
struct  await_result< Awaitable, std::enable_if_t< is_awaitable_v< Awaitable > > >
 
class  AwaitableReady
 
class  AwaitableReady< void >
 
struct  awaiter_type
 
struct  awaiter_type< Awaitable, std::enable_if_t< is_awaitable_v< Awaitable > > >
 
class  Baton
 
struct  getCurrentExecutor
 
struct  is_awaitable
 
struct  is_awaiter
 
class  Mutex
 
class  Task
 
class  TaskWithExecutor
 
class  TimedWaitAwaitable
 
class  ViaIfAsyncAwaitable
 
class  ViaIfAsyncAwaiter
 
class  Wait
 

Typedefs

template<typename Awaitable >
using awaiter_type_t = typename awaiter_type< Awaitable >::type
 
template<typename Awaitable >
using await_result_t = typename await_result< Awaitable >::type
 

Functions

template<typename Awaitable >
auto blockingWait (Awaitable &&awaitable) -> detail::decay_rvalue_reference_t< await_result_t< Awaitable >>
 
template<typename Awaitable , std::enable_if_t< folly::Conjunction< is_awaiter< Awaitable >, folly::Negation< detail::_has_free_operator_co_await< Awaitable >>, folly::Negation< detail::_has_member_operator_co_await< Awaitable >>>::value, int > = 0>
Awaitable & get_awaiter (Awaitable &&awaitable)
 
template<typename Awaitable , std::enable_if_t< detail::_has_member_operator_co_await< Awaitable >::value, int > = 0>
decltype(auto) get_awaiter (Awaitable &&awaitable)
 
template<typename Awaitable >
TimedWaitAwaitable< std::decay_t< Awaitable > > timed_wait (Awaitable &&awaitable, std::chrono::milliseconds duration)
 
template<typename Awaitable >
auto operator co_await (ViaIfAsyncAwaitable< Awaitable > &&awaitable) -> ViaIfAsyncAwaiter< folly::coro::awaiter_type_t< Awaitable >>
 
template<typename Awaitable >
auto operator co_await (ViaIfAsyncAwaitable< Awaitable > &awaitable) -> ViaIfAsyncAwaiter< folly::coro::awaiter_type_t< Awaitable & >>
 
template<typename Awaitable >
auto operator co_await (const ViaIfAsyncAwaitable< Awaitable > &&awaitable) -> ViaIfAsyncAwaiter< folly::coro::awaiter_type_t< const Awaitable && >>
 
template<typename Awaitable >
auto operator co_await (const ViaIfAsyncAwaitable< Awaitable > &awaitable) -> ViaIfAsyncAwaiter< folly::coro::awaiter_type_t< const Awaitable & >>
 
template<typename Awaitable >
auto co_viaIfAsync (folly::Executor *executor, Awaitable &&awaitable) -> ViaIfAsyncAwaitable< Awaitable >
 

Variables

template<typename T >
constexpr bool is_awaiter_v = is_awaiter<T>::value
 
template<typename T >
constexpr bool is_awaitable_v = is_awaitable<T>::value
 

Typedef Documentation

template<typename Awaitable >
using folly::coro::await_result_t = typedef typename await_result<Awaitable>::type

Definition at line 194 of file Traits.h.

template<typename Awaitable >
using folly::coro::awaiter_type_t = typedef typename awaiter_type<Awaitable>::type

await_result<Awaitable>

A template metafunction that allows you to query the type that will result from co_awaiting a value of that type in the context of a coroutine that does not modify the normal behaviour with promise_type::await_transform().

Definition at line 183 of file Traits.h.

Function Documentation

template<typename Awaitable >
auto folly::coro::blockingWait ( Awaitable &&  awaitable) -> detail::decay_rvalue_reference_t<await_result_t<Awaitable>>

blockingWait(Awaitable&&) -> await_result_t<Awaitable>

This function co_awaits the passed awaitable object and blocks the current thread until the operation completes.

This is useful for launching an asynchronous operation from the top-level main() function or from unit-tests.

WARNING: Avoid using this function within any code that might run on the thread of an executor as this can potentially lead to deadlock if the operation you are waiting on needs to do some work on that executor in order to complete.

Definition at line 313 of file BlockingWait.h.

References folly::coro::detail::makeRefBlockingWaitTask().

314  {
315  return static_cast<std::add_rvalue_reference_t<await_result_t<Awaitable>>>(
316  detail::makeRefBlockingWaitTask(static_cast<Awaitable&&>(awaitable))
317  .get());
318 }
auto makeRefBlockingWaitTask(Awaitable &&awaitable) -> BlockingWaitTask< std::add_lvalue_reference_t< Result >>
Definition: BlockingWait.h:292
template<typename Awaitable >
auto folly::coro::co_viaIfAsync ( folly::Executor executor,
Awaitable &&  awaitable 
) -> ViaIfAsyncAwaitable<Awaitable>

Returns a new awaitable that will resume execution of the awaiting coroutine on a specified executor in the case that the operation does not complete synchronously.

If the operation completes synchronously then the awaiting coroutine will continue execution on the current thread without transitioning execution to the specified executor.

Definition at line 247 of file ViaIfAsync.h.

References folly::pushmi::executor.

Referenced by folly::coro::detail::TaskPromiseBase::await_transform(), folly::Future< folly::folly::Unit >::semi(), and folly::SemiFuture< T >::within().

248  {
249  static_assert(
250  folly::coro::is_awaitable_v<Awaitable>,
251  "co_viaIfAsync() argument 2 is not awaitable.");
252  return ViaIfAsyncAwaitable<Awaitable>{executor,
253  static_cast<Awaitable&&>(awaitable)};
254 }
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
template<typename Awaitable , std::enable_if_t< folly::Conjunction< is_awaiter< Awaitable >, folly::Negation< detail::_has_free_operator_co_await< Awaitable >>, folly::Negation< detail::_has_member_operator_co_await< Awaitable >>>::value, int > = 0>
Awaitable& folly::coro::get_awaiter ( Awaitable &&  awaitable)

get_awaiter(Awaitable&&) -> awaiter_type_t<Awaitable>

The get_awaiter() function takes an Awaitable type and returns a value that contains the await_ready(), await_suspend() and await_resume() methods for that type.

This encapsulates calling 'operator co_await()' if it exists.

Definition at line 138 of file Traits.h.

Referenced by get_awaiter().

138  {
139  return awaitable;
140 }
template<typename Awaitable , std::enable_if_t< detail::_has_member_operator_co_await< Awaitable >::value, int > = 0>
decltype(auto) folly::coro::get_awaiter ( Awaitable &&  awaitable)

Definition at line 147 of file Traits.h.

References get_awaiter(), and folly::value().

147  {
148  return static_cast<Awaitable&&>(awaitable).operator co_await();
149 }
template<typename Awaitable >
auto folly::coro::operator co_await ( ViaIfAsyncAwaitable< Awaitable > &&  awaitable) -> ViaIfAsyncAwaiter<folly::coro::awaiter_type_t<Awaitable>>

Definition at line 211 of file ViaIfAsync.h.

212  {
213  return ViaIfAsyncAwaiter<folly::coro::awaiter_type_t<Awaitable>>{
214  awaitable.executor_, static_cast<Awaitable&&>(awaitable.awaitable_)};
215 }
template<typename Awaitable >
auto folly::coro::operator co_await ( ViaIfAsyncAwaitable< Awaitable > &  awaitable) -> ViaIfAsyncAwaiter<folly::coro::awaiter_type_t<Awaitable&>>

Definition at line 218 of file ViaIfAsync.h.

219  {
220  return ViaIfAsyncAwaiter<folly::coro::awaiter_type_t<Awaitable&>>{
221  awaitable.executor_, awaitable.awaitable_};
222 }
template<typename Awaitable >
auto folly::coro::operator co_await ( const ViaIfAsyncAwaitable< Awaitable > &&  awaitable) -> ViaIfAsyncAwaiter<folly::coro::awaiter_type_t<const Awaitable&&>>

Definition at line 225 of file ViaIfAsync.h.

226  {
227  return ViaIfAsyncAwaiter<folly::coro::awaiter_type_t<const Awaitable&&>>{
228  awaitable.executor_,
229  static_cast<const Awaitable&&>(awaitable.awaitable_)};
230 }
template<typename Awaitable >
auto folly::coro::operator co_await ( const ViaIfAsyncAwaitable< Awaitable > &  awaitable) -> ViaIfAsyncAwaiter<folly::coro::awaiter_type_t<const Awaitable&>>

Definition at line 233 of file ViaIfAsync.h.

234  {
235  return ViaIfAsyncAwaiter<folly::coro::awaiter_type_t<const Awaitable&>>{
236  awaitable.executor_, awaitable.awaitable_};
237 }
template<typename Awaitable >
TimedWaitAwaitable<std::decay_t<Awaitable> > folly::coro::timed_wait ( Awaitable &&  awaitable,
std::chrono::milliseconds  duration 
)

Definition at line 151 of file Utils.h.

153  {
154  return TimedWaitAwaitable<std::decay_t<Awaitable>>(
155  std::forward<Awaitable>(awaitable), duration);
156 }

Variable Documentation

template<typename T >
constexpr bool folly::coro::is_awaitable_v = is_awaitable<T>::value

Definition at line 120 of file Traits.h.

template<typename T >
constexpr bool folly::coro::is_awaiter_v = is_awaiter<T>::value

Definition at line 79 of file Traits.h.