Interface IAsyncQueueBase<TItem>
Interface that represents a queue, that can be proccessed by AsyncQueueProcessor<TItem>.
Namespace: SuperOffice.Threading
Assembly: SoCore.dll
Syntax
public interface IAsyncQueueBase<TItem>
Type Parameters
| Name | Description |
|---|---|
| TItem |
Properties
Count
Approximate count of items currently waiting in the queue (NOT including items currently being processed).
Declaration
int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
Remarks
Designed to be cheap (O(1) or O(segments)) so it is safe to call on hot paths
such as per-event diagnostic or auto-scaling decisions. Specifically does NOT
materialize a snapshot array — prefer this over ToArray(...).Length.
May read slightly stale values when other threads concurrently enqueue or
dequeue; acceptable for thresholding / metrics purposes.
HasItemsInTheQueue
True if there are items in the queue
Declaration
bool HasItemsInTheQueue { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
DrainQueue()
Discard all items currently waiting in the queue without processing them. Each discarded item's completion task is transitioned to the Canceled state, so callers awaiting an individual item or WaitForItemsInQueueToBeProcessedAsync(CancellationToken) observe cancellation rather than hanging.
Declaration
int DrainQueue()
Returns
| Type | Description |
|---|---|
| int | Number of items that were discarded. |
Remarks
Items already in flight (handed to a worker via ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken)) are NOT canceled by this method — they finish naturally. Intended for shutdown and test-isolation scenarios where the caller has given up on waiting for the remaining backlog and wants to leave the queue in a clean state for subsequent work. Workers blocked on the inner signaling primitive may observe a small, bounded number of spurious wake-ups (one per drained item) and will exit those iterations immediately when they find the queue empty.
ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken)
Process items in the queue
Declaration
Task ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem> processor, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncQueueProcessItemAsync<TItem> | processor | Processor responsible for processing each item in the queue |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken)
Process the next item in the queue. Wait for there to be an item in the queue.to start processing
Declaration
Task ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem> processor, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncQueueProcessItemAsync<TItem> | processor | Processor responsible for processing each item in the queue |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
ToArray(bool)
Get a snapshot of all the items in the queue
Declaration
TItem[] ToArray(bool includeItemsBeingProcessed)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | includeItemsBeingProcessed | Include items currently being processed in the snapshot |
Returns
| Type | Description |
|---|---|
| TItem[] |
WaitForItemsInQueueToBeProcessedAsync(CancellationToken)
Wait for all items currently in the queue or currently being processed to be processed.
Declaration
Task WaitForItemsInQueueToBeProcessedAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
This method waits for items in the queue, items being process and any overflow tasks returned by the processor.
Exceptions
| Type | Condition |
|---|---|
| AggregateException | Thrown if any of the awaiting tasks throw an exception. |
| OperationCanceledException | Thrown if the operation is canceled. |