An asynchronous, thread-safe queue for RPC requests.
More...
#include <WorkQueue.hpp>
|
| enum class | Priority : uint8_t { High
, Default
} |
| | Represents a task scheduling priority.
|
|
| | WorkQueue (std::uint32_t numWorkers, uint32_t maxSize=0) |
| | Create an instance of the work queue.
|
| | WorkQueue (DontStartProcessingTag, std::uint32_t numWorkers, uint32_t maxSize=0) |
| | Create an instance of the work queue without starting the processing of events.
|
|
void | startProcessing () |
| | Start processing of the enqueued tasks.
|
| void | requestStop (std::function< void()> onQueueEmpty=[] {}) |
| | Put the work queue into a stopping state. This will prevent new jobs from being queued.
|
|
void | stop () |
| | Put the work queue into a stopping state and await workers to finish.
|
| bool | postCoro (TaskType func, bool isWhiteListed, Priority priority=Priority::Default) |
| | Submit a job to the work queue.
|
| boost::json::object | report () const override |
| | Generate a report of the work queue state.
|
|
void | join () |
| | Wait until all the jobs in the queue are finished.
|
| size_t | size () const |
| | Get the size of the queue.
|
An asynchronous, thread-safe queue for RPC requests.
◆ WorkQueue() [1/2]
| rpc::WorkQueue::WorkQueue |
( |
std::uint32_t | numWorkers, |
|
|
uint32_t | maxSize = 0 ) |
Create an instance of the work queue.
The work queue immediately starts to process tasks as they come.
- Parameters
-
| numWorkers | The amount of threads to spawn in the pool |
| maxSize | The maximum capacity of the queue; 0 means unlimited |
◆ WorkQueue() [2/2]
Create an instance of the work queue without starting the processing of events.
Clients are expected to call startProcessing manually once ready to start processing tasks.
- Parameters
-
| numWorkers | The amount of threads to spawn in the pool |
| maxSize | The maximum capacity of the queue; 0 means unlimited |
◆ makeWorkQueue()
A factory function that creates the work queue based on a config.
- Parameters
-
| config | The Clio config to use |
- Returns
- The work queue
◆ postCoro()
| bool rpc::WorkQueue::postCoro |
( |
TaskType | func, |
|
|
bool | isWhiteListed, |
|
|
Priority | priority = Priority::Default ) |
Submit a job to the work queue.
The job will be rejected if isWhiteListed is set to false and the current size of the queue reached capacity.
- Parameters
-
| func | The function object to queue as a job |
| isWhiteListed | Whether the queue capacity applies to this job |
| priority | The priority of the task |
- Returns
- true if the job was successfully queued; false otherwise
◆ report()
| boost::json::object rpc::WorkQueue::report |
( |
| ) |
const |
|
nodiscardoverridevirtual |
Generate a report of the work queue state.
- Returns
- The report as a JSON object.
Implements rpc::Reportable.
◆ requestStop()
| void rpc::WorkQueue::requestStop |
( |
std::function< void()> | onQueueEmpty = [] {} | ) |
|
Put the work queue into a stopping state. This will prevent new jobs from being queued.
- Parameters
-
| onQueueEmpty | A callback to run when the last task in the queue is completed |
◆ size()
| size_t rpc::WorkQueue::size |
( |
| ) |
const |
|
nodiscard |
Get the size of the queue.
- Returns
- The number of jobs in the queue.
The documentation for this class was generated from the following files:
- /__w/clio/clio/src/rpc/WorkQueue.hpp
- /__w/clio/clio/src/rpc/WorkQueue.cpp