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

Distributes single event to multiple coroutines (subscribbers) More...

#include <distributor.h>

Public Types

template<typename QueueImpl = typename queue<T>::behavior>
using queue = distributor_queue< T, Lock, QueueImpl >
 Implements queue above distributor. More...
 

Public Member Functions

 distributor ()=default
 default constructor More...
 
 distributor (Lock &&lk)
 initialize lock instance More...
 
template<typename ... Args>
void publish (Args &&... args)
 publish the value More...
 
void cancel_all ()
 drops all subscribers More...
 
void reject_all (std::exception_ptr e)
 reject all with exception More...
 
void reject_all ()
 reject all with current exception More...
 
subscription subscribe (ID id={ })
 subscribe More...
 
pending_notify drop (ID id)
 drop single subscriber More...
 

Detailed Description

template<typename T, typename Lock = nolock>
class coro::distributor< T, Lock >

Distributes single event to multiple coroutines (subscribbers)

To use this object, a consument must subscribe itself at this object by calling subscribe() method. Return value is lazy_future. It must be awaited to finish subscribtion. To distribute event, you need to publish the event. The method resumes all registered coroutines.

Every subscription is one-shot. If the coroutine need to continue in subscription, it must re-call subscribe() right after resumption (in the same thread, without calling another co_await). If the subscriber need to process result asynchronously, it need to use distributor::queue to push received results to an queue, which can be also co_awaited

Template Parameters
Ttype which is payload of distribution. Can be reference
Locklocking class. Default value disables locking for better performace. You need to set to std::mutex, if you need MT Safety

Definition at line 46 of file distributor.h.


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