ecor
Loading...
Searching...
No Matches
ecor::task< T, CFG > Struct Template Reference

Task type that represents an asynchronous operation that is implemented as a coroutine and is a sender. More...

#include <ecor.hpp>

Public Types

using completion_signatures = _sigs_append_t< _error_completions, _value_setter_t< T >, set_stopped_t() >
 
using promise_type = _promise_type< task, CFG >
 
using sender_concept = sender_t
 
using value_type = T
 

Public Member Functions

template<receiver R>
auto connect (R receiver) &&
 Connect the task to a receiver. More...
 
taskoperator= (task &&other) noexcept
 
taskoperator= (task const &)=delete
 
 task (std::coroutine_handle< promise_type > handle, task_error error=task_error::none) noexcept
 Constructor used by promise_type for coroutine creation.
 
 task (task &&other) noexcept
 
 task (task const &)=delete
 

Detailed Description

template<typename T, task_config CFG>
struct ecor::task< T, CFG >

Task type that represents an asynchronous operation that is implemented as a coroutine and is a sender.

The task type is parameterized by the value type it provides, and an optional configuration type that specifies additional behavior during compilation.

Task expectes argument satisfying task_context concept to be passed to the coroutine as first argument. This is used to provide the task with necessary runtime resources, such as the task core for scheduling and the task memory resource for dynamic memory allocation.

Task can be scheduled and processed as normal sender in the sender/receiver framework. The task has capability to co_await any sender as long as:

  • The sender has at most one set_value completion_signature.
  • The sender has only set_error completions that are compatible with the current task.
  • Note: The sender can have set_stopped completion signature. As a consequence of task being a sender and being able to await sender - tasks can await other tasks.

Task always starts suspended and only starts execution after start() was called on the operation state returned by connect().

When co_awaiting on a sender, the task will suspend until the sender completes, value signal of sender does not immediately resume the task, but instead the task is scheduled to be resumed by the task core. In case of an error or stop signal from the sender, the task will not be resumed, but instead the error or stop signal will be immediately propagated to the task's receiver, and the task will be considered completed and will be destructed.

Task completion signature is always fixed and independent of the content of the coroutine itself, or the receiver environment:

  • set_value_t( value_type ) where value_type is the type specified by the user as the first template parameter of the task. If the value type is void, then the set_value signature is set_value_t().
  • set_error_t( task_error ) - This is the default error signature that all tasks have, and it is used to report errors that occur during the execution of the task, such as allocation failures or unfinished
  • Additional error signatures specified by the user in the task configuration.
  • set_stopped_t() - This is used to report that the task was stopped before it could complete, either by the user or by the library.

Member Function Documentation

◆ connect()

template<typename T , task_config CFG>
template<receiver R>
auto ecor::task< T, CFG >::connect ( receiver) &&
inline

Connect the task to a receiver.

This returns an operation state that can be started to begin the execution of the task.

The operation is expected to be destructive, the task can't be connected again after connect call.


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