Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
asyncpp::queue< T, TContainer > Class Template Reference

Queue for sharing items between multiple producers/consumers. More...

#include <asyncpp/queue.h>

Classes

class  pop_awaiter
 
class  push_awaiter
 

Public Member Functions

template<typename... Args>
 queue (size_t max_size=std::numeric_limits< size_t >::max(), dispatcher *disp=nullptr, Args &&... args)
 Construct a new queue.
 
 queue (const queue &)=delete
 
 queue (queue &&) noexcept
 
queueoperator= (const queue &)=delete
 
queueoperator= (queue &&) noexcept
 
size_t size () const noexcept
 Get the number of items available without suspending.
 
bool empty () const noexcept
 True if the queue is empty and calling pop() would suspend.
 
bool try_push (T &&value)
 Try pushing a new item to the queue.
 
template<typename... Args>
bool try_emplace (Args &&... args)
 Try pushing a new item to the queue.
 
std::optional< T > try_pop ()
 Try poping a item from the queue.
 
pop_awaiter pop ()
 Pop a value from the queue and suspend if the queue is empty.
 
push_awaiter push (T &&value)
 Push a value to the queue and suspend if the queue is full.
 
void clear ()
 Clear the queue.
 

Detailed Description

template<typename T, typename TContainer = std::deque<T>>
class asyncpp::queue< T, TContainer >

Queue for sharing items between multiple producers/consumers.

Constructor & Destructor Documentation

◆ queue()

template<typename T , typename TContainer = std::deque<T>>
template<typename... Args>
asyncpp::queue< T, TContainer >::queue ( size_t max_size = std::numeric_limits<size_t>::max(),
dispatcher * disp = nullptr,
Args &&... args )
inlineexplicit

Construct a new queue.

Parameters
max_sizeThe maximum size of items being stored inside the queue before suspending producers.
dispA default dispatcher to use for resuming pop/push operations
argsArguments passed to the underlying std::queue constructor

Member Function Documentation

◆ push()

template<typename T , typename TContainer >
queue< T, TContainer >::push_awaiter asyncpp::queue< T, TContainer >::push ( T && value)
inline

Push a value to the queue and suspend if the queue is full.

Parameters
valueThe item to push

◆ size()

template<typename T , typename TContainer >
size_t asyncpp::queue< T, TContainer >::size ( ) const
inlinenoexcept

Get the number of items available without suspending.

Returns
Number of items until pop() blocks
Note
The number returned by size() can exceed the maximum set in the constructor, because it includes tasks suspended in push().

◆ try_emplace()

template<typename T , typename TContainer >
template<typename... Args>
bool asyncpp::queue< T, TContainer >::try_emplace ( Args &&... args)
inline

Try pushing a new item to the queue.

Parameters
valueThe item to push
Returns
true if the item was pushed to the queue, false if the queue is full

◆ try_pop()

template<typename T , typename TContainer >
std::optional< T > asyncpp::queue< T, TContainer >::try_pop ( )
inline

Try poping a item from the queue.

Returns
The removed item or std::nullopt if the queue is empty

◆ try_push()

template<typename T , typename TContainer >
bool asyncpp::queue< T, TContainer >::try_push ( T && value)
inline

Try pushing a new item to the queue.

Parameters
valueThe item to push
Returns
true if the item was pushed to the queue, false if the queue is full

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