asynchrony 0.0.0
Add asynchrony to your C++ applications using standard C++20
Loading...
Searching...
No Matches
siddiqsoft::simple_worker< T, Pri > Struct Template Reference

Implements a simple queue + semaphore driven asynchronous processor. More...

#include </opt/azure-agent/_work/14/s/include/siddiqsoft/simple_worker.hpp>

Public Member Functions

 simple_worker (const simple_worker &)=delete
simple_worker & operator= (const simple_worker &)=delete
void forceCleanupTerminate (const std::source_location &sl=std::source_location::current())
 This method is to be used by the user when they shutdown their application. This is best used for cases when the callback cannot be guaranteed to be "clean" or respect the stop_token.
 simple_worker (simple_worker &&)=delete
 Move constructor and assignment are disallowed to avoid transferring thread ownership.
simple_worker & operator= (simple_worker &&)=delete
 simple_worker (std::function< void(T &&)> c)
 Constructor requires the callback for the thread.
void queue (T &&item)
 Queue item into this worker thread's deque.

Static Public Attributes

static constexpr std::chrono::milliseconds DEFAULT_WAIT_FOR_NEXT_ITEM_MS {1500}

Detailed Description

template<typename T, int Pri = 0>
requires ((Pri >= -10) && (Pri <= 10)) && std::move_constructible<T>
struct siddiqsoft::simple_worker< T, Pri >

Implements a simple queue + semaphore driven asynchronous processor.

Template Parameters
TThe data type for this processor
PriOptional thread priority level. 0=Normal

Definition at line 72 of file simple_worker.hpp.

Constructor & Destructor Documentation

◆ ~simple_worker()

template<typename T, int Pri = 0>
siddiqsoft::simple_worker< T, Pri >::~simple_worker ( )
inline

Definition at line 81 of file simple_worker.hpp.

◆ simple_worker()

template<typename T, int Pri = 0>
siddiqsoft::simple_worker< T, Pri >::simple_worker ( std::function< void(T &&)> c)
inline

Constructor requires the callback for the thread.

Parameters
cThe callback which accepts the type T as reference and performs action.

Definition at line 144 of file simple_worker.hpp.

Member Function Documentation

◆ forceCleanupTerminate()

template<typename T, int Pri = 0>
void siddiqsoft::simple_worker< T, Pri >::forceCleanupTerminate ( const std::source_location & sl = std::source_location::current())
inline

This method is to be used by the user when they shutdown their application. This is best used for cases when the callback cannot be guaranteed to be "clean" or respect the stop_token.

Definition at line 102 of file simple_worker.hpp.

◆ queue()

template<typename T, int Pri = 0>
void siddiqsoft::simple_worker< T, Pri >::queue ( T && item)
inline

Queue item into this worker thread's deque.

Parameters
itemThis is move'd into the internal deque

Definition at line 152 of file simple_worker.hpp.

Member Data Documentation

◆ DEFAULT_WAIT_FOR_NEXT_ITEM_MS

template<typename T, int Pri = 0>
std::chrono::milliseconds siddiqsoft::simple_worker< T, Pri >::DEFAULT_WAIT_FOR_NEXT_ITEM_MS {1500}
staticconstexpr

Definition at line 74 of file simple_worker.hpp.


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