libcoro  1.0
Coroutine support library for C++20
Public Member Functions | List of all members
coro::async< T, Alloc > Class Template Reference

COROUTINE: Coroutine for asynchronous operation. More...

#include <async.h>

Public Member Functions

 async ()=default
 construct uninitialized object More...
 
template<typename A >
 async (async< T, A > &&other)
 convert from different allocator (because the allocator is only used during creation) More...
 
void detach ()
 Run coroutine detached. More...
 
std::coroutine_handle detach_on_await_suspend ()
 detach coroutine using symmetric transfer More...
 
future< T > start ()
 Start coroutine and return future. More...
 
void start (promise< T > prom)
 Start coroutine and pass return value to promise. More...
 
deferred_future< T > defer_start ()
 Defer start of coroutine. More...
 
shared_future< T > shared_start ()
 Start coroutine and return shared future. More...
 
future< T > operator co_await ()
 direct co_await More...
 
 operator future< T > ()
 convert coroutine to future, start immediatelly More...
 
 operator deferred_future< T > ()
 convert to deferred_future More...
 
 operator shared_future< T > ()
 convert to shared_future More...
 
template<std::constructible_from< T > U>
 operator U ()
 synchronous wait for value More...
 
auto run ()
 run synchronously More...
 

Detailed Description

template<typename T, coro_allocator Alloc = std_allocator>
class coro::async< T, Alloc >

COROUTINE: Coroutine for asynchronous operation.

This represents a coroutine which can return a value. The object returned by the coroutine can be converted to future<T> or deferred_future<T>, or can be directly co_awaited. You can also convert this object to T to retrieve value synchronously

async<int> my_coro(...) {
//...
co_return 42;
}

Synchronous access

int val = my_coro(...)

Retrieve future

future<int> f = my_coro(...);
int val = co_await f;

Direct co_await

int val = co_await my_coro(...);
Template Parameters
Ttype of returned value
Allocoptional allocator
Note
object is movable only ,

Definition at line 55 of file async.h.


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