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

Future which can be shared (by copying - like shared_ptr) More...

#include <future.h>

+ Collaboration diagram for coro::shared_future< T >:

Public Member Functions

 shared_future ()
 Construct shared future uninitialized. More...
 
template<typename Arg0 , typename ... Args>
 requires (!std::is_same_v< std::decay_t< Arg0 >, shared_future >) shared_future(Arg0 &&arg0
 Construct shared future initialize it same way asi coro::future. More...
 
 shared_future (shared_future &other)
 shared future is copyable More...
 
 shared_future (const shared_future &other)
 shared future is copyable More...
 
shared_futureoperator= (const shared_future &other)
 you can assign More...
 
 ~shared_future ()
 destructor More...
 
promise< T > get_promise ()
 Initialize future and get promise. More...
 
template<typename stl_allocator >
promise< T > get_promise (stl_allocator &&allocator)
 Initialize future and get promise. More...
 
template<std::invocable<> Fn>
void operator<< (Fn &&fn)
 Redirect return value of function returning coro::future to instance of shared_future. More...
 
template<std::invocable<> Fn, typename std_allocator >
void operator<< (std::tuple< Fn, std_allocator > &&tpl)
 Redirect return value of function returning coro::future to instance of shared_future. More...
 
template<std::invocable<> Fn>
bool set_callback (Fn &&fn)
 set callback which is invoked when future is resolved More...
 
template<std::invocable<> Fn>
bool then (Fn &&fn)
 execute callback when future is resolved More...
 
template<std::invocable<> Fn>
bool operator>> (Fn &&fn)
 alias to then() More...
 
wait_awaiter wait ()
 Perform synchronous wait on resolution. More...
 
ret_value get ()
 Retrieves value, performs synchronous wait. More...
 
 operator cast_ret_value ()
 Retrieves value, performs synchronous wait. More...
 
bool is_pending () const
 Determines pending status. More...
 
bool is_in_progress () const
 Determine in progress status. More...
 
bool is_awaited () const
 Determine whether an awaiter is set. More...
 
bool await_ready () const
 co_await support, returns true, if value is ready (resolved) More...
 
bool await_suspend (std::coroutine_handle<> h)
 co_await support, called with suspended coroutine More...
 
void reset ()
 reset state More...
 
bool has_value () const
 Determines, whether future has a value. More...
 
bool has_exception () const
 Determines, whether future has exception. More...
 
canceled_awaiter operator! ()
 awaitable for canceled operation More...
 

Protected Types

enum class  State : char { unused , awaited , notified }
 

Detailed Description

template<typename T>
class coro::shared_future< T >

Future which can be shared (by copying - like shared_ptr)

Each instance of the shared future can be awaited or can install a callback function. So this allows to have multiple awaiters on signle future. The shared future can be constructed by similar wait as future, you can retrieve promise<T> or you can convert future<T> to shared_future<T> by passing a function call returning future<T> to a constructor of shared_future<T>

future<int> foo(...);
shared_future<int> fut( [&]{return foo(...);} );
Template Parameters
T

Definition at line 1406 of file future.h.


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