Interface IAsyncWorkerData
Runtime data container interface for a centralized async work queue. Provides bounded, backpressure-aware enqueueing of async work items, executed concurrently under a configurable concurrency limit.
Systems use this instead of fire-and-forget _ = SomeAsync(...)
to bound how much work is in flight at once and to get ordering
guarantees for entity-keyed work.
public interface IAsyncWorkerData : IRuntimeDataContainer, IServerComponent
Properties
CompletedCount
Total number of work items processed since startup.
long CompletedCount { get; }
Property Value
PendingCount
Current number of items accepted but not yet started. Useful for monitoring and diagnostics.
int PendingCount { get; }
Property Value
Methods
Enqueue(Func<Task>, long, string)
Enqueue an async work item with an entity key for ordered processing. Work items sharing the same entityKey are guaranteed to execute in FIFO order, one at a time; items with different keys proceed independently. Returns true if the item was accepted, false if the queue is full (backpressure).
bool Enqueue(Func<Task> work, long entityKey, string callerName = null)
Parameters
workFunc<Task>The async work to execute.
entityKeylongEntity identifier for ordering (e.g., characterID), or 0 for none.
callerNamestringOptional caller identifier for diagnostics.
Returns
- bool
True if enqueued successfully.
Remarks
An entityKey of 0 means "no ordering requirement" and is treated
exactly like the unkeyed overload. It is not an entity whose id happens to be zero, and
callers that pass a default id are not asking to be serialized with each other.
Enqueue(Func<Task>, string)
Enqueue an async work item for processing. Returns true if the item was accepted, false if the queue is full (backpressure).
bool Enqueue(Func<Task> work, string callerName = null)
Parameters
workFunc<Task>The async work to execute.
callerNamestringOptional caller identifier for diagnostics.
Returns
- bool
True if enqueued successfully.
EnqueueRequired(Func<Task>, long, string)
Admits work that must not be refused for being over the backpressure threshold — a write whose in-memory state has already been committed, so dropping it would lose data.
AsyncWorkAdmission EnqueueRequired(Func<Task> work, long entityKey, string callerName = null)
Parameters
workFunc<Task>The async work to execute.
entityKeylongEntity identifier for ordering, or 0 for none.
callerNamestringOptional caller identifier for diagnostics.
Returns
- AsyncWorkAdmission
Whether the work was admitted, and whether it was over the threshold. Refused only when the pool is not running at all (not yet initialised, or shutting down).
Remarks
Past the threshold the item is still admitted, still runs under the same concurrency cap as everything else, and still keeps its place in its entity's order. What it does not do is run immediately: it waits for a slot like any other item.
This replaces the caller-side fallback that ran over-threshold persistence on the thread pool directly. That fallback was outside the concurrency cap, so a database stall that filled the queue turned into an unbounded number of concurrent writes against the connection pool — which then timed out, filed repairs, and queued more writes — and it broke the per-entity order the incremental item writes rely on, at exactly the moment the server was busiest.
Items admitted over the threshold still count towards it, so ordinary Enqueue(Func<Task>, string) callers keep seeing backpressure until the backlog drains.