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

Implements asychronous queue with support for coroutines. More...

#include <queue.h>

Public Member Functions

 queue ()=default
 Construct default queue. More...
 
template<std::convertible_to< QueueImpl > Q>
 queue (Q &&qimpl)
 Construct queue - initialize internal queue object. More...
 
 queue (const queue &other)=delete
 The queue is not copyable. More...
 
 queue (queue &&other)
 The queue is movable. More...
 
template<typename ... Args>
promise< T >::notify emplace (Args &&... args)
 Push the item to the queue (emplace) More...
 
auto push (const T &x)
 Push item to the queue. More...
 
auto push (T &&x)
 Push item to the queue. More...
 
future< T > pop ()
 Pop the items. More...
 
promise< T >::notify pop (promise< T > &prom)
 Pop item into a promise. More...
 
std::optional< T > try_pop ()
 Pops item non-blocking way. More...
 
bool empty () const
 determines whether queue is empty More...
 
std::size_t size () const
 retrieve current size of the queue More...
 
void clear ()
 remove all items from the queue More...
 
void close (std::exception_ptr e=nullptr)
 close the queue More...
 
void reopen ()
 Reactivates the queue. More...
 

Detailed Description

template<typename T, typename QueueImpl = std::queue<T>>
class coro::queue< T, QueueImpl >

Implements asychronous queue with support for coroutines.

Asynchronous queue allows to co_await on new items. You can have multiple coroutines reading the same queue (for push-pull)

Template Parameters
Ttype of item
QueueImplobject which implements the queue, default is std::queue. You can use for example some kind of priority queue or stack, however the object must have the same interface as the std::queue

Definition at line 22 of file queue.h.


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