Lightweight 0.20260617.0
Loading...
Searching...
No Matches
Lightweight::Async::StrandExecutor Class Referencefinal

#include <StrandExecutor.hpp>

Inheritance diagram for Lightweight::Async::StrandExecutor:
Lightweight::Async::IExecutor Lightweight::Async::IResumeScheduler

Public Member Functions

 StrandExecutor (IExecutor &underlying)
 
 StrandExecutor (StrandExecutor const &)=delete
 
StrandExecutoroperator= (StrandExecutor const &)=delete
 
 StrandExecutor (StrandExecutor &&)=delete
 
StrandExecutoroperator= (StrandExecutor &&)=delete
 
void Post (Work work) override
 
void Resume (std::coroutine_handle<> handle) override
 
- Public Member Functions inherited from Lightweight::Async::IExecutor
 IExecutor (IExecutor const &)=delete
 
IExecutoroperator= (IExecutor const &)=delete
 
 IExecutor (IExecutor &&)=delete
 
IExecutoroperator= (IExecutor &&)=delete
 
- Public Member Functions inherited from Lightweight::Async::IResumeScheduler
 IResumeScheduler (IResumeScheduler const &)=delete
 
IResumeScheduleroperator= (IResumeScheduler const &)=delete
 
 IResumeScheduler (IResumeScheduler &&)=delete
 
IResumeScheduleroperator= (IResumeScheduler &&)=delete
 

Detailed Description

Serializes work over an underlying executor (an Asio-style "strand").

All work posted to a given strand runs one item at a time, in FIFO order, even though the items execute on the underlying executor's worker threads. This guarantees that a single ODBC connection — which is not safe for concurrent use — is touched by only one thread at a time. A strand does not own a thread; it borrows the underlying executor.

The strand's mutable state lives in a heap State held by a std::shared_ptr. Each in-flight drain closure keeps a copy of that pointer, so the state outlives the StrandExecutor wrapper itself until the last drain returns. This makes the strand safe to destroy (or to replace, e.g. via SqlConnection::EnableAsync) while a drain is still running on a worker thread — the closure only ever touches State, never the wrapper.

Definition at line 25 of file StrandExecutor.hpp.

Constructor & Destructor Documentation

◆ StrandExecutor()

Lightweight::Async::StrandExecutor::StrandExecutor ( IExecutor underlying)
explicit

Constructs a strand layered over underlying.

Parameters
underlyingThe executor that actually runs the serialized work.

Member Function Documentation

◆ Post()

void Lightweight::Async::StrandExecutor::Post ( Work  work)
overridevirtual

Schedules work to run on the executor. Thread-safe.

Parameters
workThe work item to enqueue (consumed).

Implements Lightweight::Async::IExecutor.

◆ Resume()

void Lightweight::Async::StrandExecutor::Resume ( std::coroutine_handle<>  handle)
overridevirtual

Schedules handle to be resumed. Thread-safe.

Parameters
handleThe coroutine to resume.

Implements Lightweight::Async::IResumeScheduler.


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