#include <Pt/Coroutine.h>
Provides the base class for I/O-driven co_await-able operations. More...
Inherits AwaiterBase.
Inherited by BasicAwaiter< void >, BasicAwaiter< R >, BasicAwaiter< void >, ConnectionAwaiter, AsyncAdvance, and AsyncYield.
Protected Member Functions | |
| Awaiter () | |
| Constructor. | |
| void | setReady () |
| Resumes the waiting coroutine. | |
| virtual void | onBegin ()=0 |
| Starts the asynchronous operation. | |
| virtual void | onCancel ()=0 |
| Aborts the in-flight operation. | |
Derive from Awaiter to wrap an asynchronous operation so a Task or Generator can suspend until it completes. Implement Awaiter::onBegin() to subscribe to completion and start the work. Implement Awaiter::onCancel() to abort that work. Call Awaiter::setReady() when the operation finishes; that resumes the waiting coroutine.
Implement await_resume() in the subclass to deliver the result, or derive from BasicAwaiter when the awaitable only needs to produce a value through BasicAwaiter::onReady().
The following awaiter starts a device operation and resumes when the device signals completion:
|
protected |
Call this when the asynchronous operation has completed. Typically connect a completion signal to this method.
|
protectedpure virtual |
Subscribe to completion and begin the work. The coroutine remains suspended until Awaiter::setReady() is called.
Implemented in AsyncYield.
|
protectedpure virtual |
Called from Awaiter::cancel() when the waiting task or generator is cancelled.
Implemented in ConnectionAwaiter, and AsyncYield.