NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
neograph::util::RequestQueue Class Reference

Lock-free task queue with a fixed worker thread pool and backpressure. More...

#include <request_queue.h>

Classes

struct  Stats
 Runtime statistics for monitoring queue health. More...
 

Public Member Functions

 RequestQueue (size_t num_workers=128, size_t max_queue_size=10000)
 Construct a request queue with a worker thread pool.
 
Stats stats () const
 Get current queue statistics.
 
template<typename F >
std::pair< bool, std::future< void > > submit (F &&task)
 Submit a task to the queue.
 
 ~RequestQueue ()
 Destructor: stops all workers and waits for them to finish.
 

Detailed Description

Lock-free task queue with a fixed worker thread pool and backpressure.

Tasks are submitted via submit() and executed asynchronously by worker threads. When the queue is full, new tasks are rejected (backpressure).

RequestQueue queue(4, 1000); // 4 workers, max 1000 pending tasks
auto [accepted, future] = queue.submit([]{ do_work(); });
if (accepted) future.wait();
Lock-free task queue with a fixed worker thread pool and backpressure.

Definition at line 35 of file request_queue.h.

Constructor & Destructor Documentation

◆ RequestQueue()

neograph::util::RequestQueue::RequestQueue ( size_t  num_workers = 128,
size_t  max_queue_size = 10000 
)
inline

Construct a request queue with a worker thread pool.

Parameters
num_workersNumber of worker threads to spawn (default: 128).
max_queue_sizeMaximum number of pending tasks before backpressure (default: 10000).

Definition at line 52 of file request_queue.h.

Member Function Documentation

◆ stats()

Stats neograph::util::RequestQueue::stats ( ) const
inline

Get current queue statistics.

Returns
Stats snapshot with pending, active, completed, and rejected counts.

Definition at line 117 of file request_queue.h.

◆ submit()

template<typename F >
std::pair< bool, std::future< void > > neograph::util::RequestQueue::submit ( F &&  task)
inline

Submit a task to the queue.

If the queue is full (pending >= max_queue_size), the task is rejected and the rejected counter is incremented.

Template Parameters
FCallable type (must be invocable with no arguments).
Parameters
taskThe task to execute.
Returns
A pair of {accepted, future}: accepted is true if the task was enqueued; future can be waited on for completion. If rejected, future is default-constructed (invalid).

Definition at line 89 of file request_queue.h.


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