C/C++ API Reference
Loading...
Searching...
No Matches
pw::async2::Context Class Reference

Overview

Context for an asynchronous Task.

This object contains resources needed for scheduling asynchronous work, such as the current Dispatcher and the Waker for the current task.

Context s are most often created by Dispatcher s, which pass them into Task::Pend.

Public Member Functions

 Context (Dispatcher &dispatcher, Waker &waker)
 
Dispatcherdispatcher ()
 
void ReEnqueue ()
 
template<typename T = ReadyType>
Poll< T > Unschedule ()
 

Friends

class NativeDispatcherBase
 
bool internal::StoreWaker (Context &cx, Waker &waker_out, log::Token wait_reason)
 
bool internal::StoreWaker (Context &cx, internal::WakerQueueBase &queue, log::Token wait_reason)
 

Constructor & Destructor Documentation

◆ Context()

pw::async2::Context::Context ( Dispatcher dispatcher,
Waker waker 
)
inline

Creates a new Context containing the currently-running Dispatcher and a Waker for the current Task.

Member Function Documentation

◆ dispatcher()

Dispatcher & pw::async2::Context::dispatcher ( )
inline

The Dispatcher on which the current Task is executing.

This can be used for spawning new tasks using dispatcher().Post(task);.

◆ ReEnqueue()

void pw::async2::Context::ReEnqueue ( )

Queues the current Task::Pend to run again in the future, possibly after other work is performed.

This may be used by Task implementations that wish to provide additional fairness by yielding to the dispatch loop rather than perform too much work in a single iteration.

This is semantically equivalent to calling:

Waker waker;
PW_ASYNC_STORE_WAKER(cx, waker, ...);
std::move(waker).Wake();
Definition: waker.h:160
#define PW_ASYNC_STORE_WAKER(context, waker_or_queue_out, wait_reason_string)
Definition: waker.h:60

◆ Unschedule()

template<typename T = ReadyType>
Poll< T > pw::async2::Context::Unschedule ( )
inline

Indicates that the task has not completed, but that it also does not need to register a waker and go to sleep. This results in the task being removed from the dispatcher, requiring it to be manually re-posted to run again.


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