proxygen
folly::coro::Task< T > Class Template Reference

#include <Task.h>

Public Types

using promise_type = detail::TaskPromise< T >
 

Public Member Functions

 Task (const Task &t)=delete
 
 Task (Task &&t) noexcept
 
 ~Task ()
 
Taskoperator= (Task t) noexcept
 
void swap (Task &t) noexcept
 
FOLLY_NODISCARD TaskWithExecutor< TscheduleOn (Executor *executor)&&noexcept
 

Private Types

using handle_t = std::experimental::coroutine_handle< promise_type >
 

Private Member Functions

 Task (handle_t coro) noexcept
 

Private Attributes

handle_t coro_
 

Friends

class detail::TaskPromiseBase
 
class detail::TaskPromise< T >
 

Detailed Description

template<typename T>
class folly::coro::Task< T >

Represents an allocated, but not-started coroutine, which is not yet been bound to an executor.

You can only co_await a Task from within another Task, in which case it is implicitly bound to the same executor as the parent Task.

Alternatively, you can explicitly provide an executor by calling the task.scheduleOn(executor) method, which will return a new not-yet-started TaskWithExecutor that can be co_awaited anywhere and that will automatically schedule the coroutine to start executing on the bound executor when it is co_awaited.

Within the body of a Task's coroutine, it will ensure that it always executes on the bound executor by implicitly transforming every 'co_await expr' expression into `co_await co_viaIfAsync(boundExecutor, expr)' to ensure that the coroutine always resumes on the executor.

Definition at line 38 of file Task.h.

Member Typedef Documentation

template<typename T>
using folly::coro::Task< T >::handle_t = std::experimental::coroutine_handle<promise_type>
private

Definition at line 267 of file Task.h.

template<typename T>
using folly::coro::Task< T >::promise_type = detail::TaskPromise<T>

Definition at line 264 of file Task.h.

Constructor & Destructor Documentation

template<typename T>
folly::coro::Task< T >::Task ( const Task< T > &  t)
delete
template<typename T>
folly::coro::Task< T >::Task ( Task< T > &&  t)
inlinenoexcept

Definition at line 272 of file Task.h.

272 : coro_(std::exchange(t.coro_, {})) {}
handle_t coro_
Definition: Task.h:305
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
template<typename T>
folly::coro::Task< T >::~Task ( )
inline

Definition at line 274 of file Task.h.

274  {
275  if (coro_) {
276  coro_.destroy();
277  }
278  }
handle_t coro_
Definition: Task.h:305
template<typename T>
folly::coro::Task< T >::Task ( handle_t  coro)
inlineprivatenoexcept

Definition at line 303 of file Task.h.

303 : coro_(coro) {}
handle_t coro_
Definition: Task.h:305

Member Function Documentation

template<typename T>
Task& folly::coro::Task< T >::operator= ( Task< T t)
inlinenoexcept

Definition at line 280 of file Task.h.

References folly::swap(), and folly::pushmi::detail::t.

280  {
281  swap(t);
282  return *this;
283  }
void swap(Task &t) noexcept
Definition: Task.h:285
template<typename T>
FOLLY_NODISCARD TaskWithExecutor<T> folly::coro::Task< T >::scheduleOn ( Executor executor)
inlinenoexcept

Specify the executor that this task should execute on.

Returns a new task that when co_awaited will launch execution of this task on the specified executor.

Definition at line 294 of file Task.h.

References folly::exchange(), and folly::pushmi::executor.

294  {
295  coro_.promise().executor_ = executor;
296  return TaskWithExecutor<T>{std::exchange(coro_, {})};
297  }
handle_t coro_
Definition: Task.h:305
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
template<typename T>
void folly::coro::Task< T >::swap ( Task< T > &  t)
inlinenoexcept

Definition at line 285 of file Task.h.

References FOLLY_NODISCARD, folly::f14::swap(), and folly::pushmi::detail::t.

285  {
286  std::swap(coro_, t.coro_);
287  }
handle_t coro_
Definition: Task.h:305
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414

Friends And Related Function Documentation

template<typename T>
friend class detail::TaskPromise< T >
friend

Definition at line 301 of file Task.h.

template<typename T>
friend class detail::TaskPromiseBase
friend

Definition at line 300 of file Task.h.

Member Data Documentation

template<typename T>
handle_t folly::coro::Task< T >::coro_
private

Definition at line 305 of file Task.h.


The documentation for this class was generated from the following file: