Class AsyncQueueBase<TItem>
Default implementation of IAsyncQueueBase<TItem> base functionality
Inherited Members
Namespace: SuperOffice.Threading
Assembly: SoCore.dll
Syntax
public abstract class AsyncQueueBase<TItem> : IAsyncQueueBase<TItem>, IAsyncQueueInstance
Type Parameters
| Name | Description |
|---|---|
| TItem | Item in the queue |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
Constructors
AsyncQueueBase(INSPrincipalAccessor, ILogger<AsyncQueueBase<TItem>>, AsyncQueueTracker)
Default constructor
Declaration
protected AsyncQueueBase(INSPrincipalAccessor principalAccessor, ILogger<AsyncQueueBase<TItem>> logger, AsyncQueueTracker tracker)
Parameters
| Type | Name | Description |
|---|---|---|
| INSPrincipalAccessor | principalAccessor | |
| ILogger<AsyncQueueBase<TItem>> | logger | |
| AsyncQueueTracker | tracker |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
Fields
_dequeueLock
Default implementation of IAsyncQueueBase<TItem> base functionality
Declaration
protected readonly object _dequeueLock
Field Value
| Type | Description |
|---|---|
| object |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
_endOfProcessingCancellation
Default implementation of IAsyncQueueBase<TItem> base functionality
Declaration
protected readonly CancellationTokenSource _endOfProcessingCancellation
Field Value
| Type | Description |
|---|---|
| CancellationTokenSource |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
_itemsBeingProcessed
Default implementation of IAsyncQueueBase<TItem> base functionality
Declaration
protected readonly ConcurrentDictionary<Guid, AsyncQueueBase<TItem>.AsyncQueueItem> _itemsBeingProcessed
Field Value
| Type | Description |
|---|---|
| ConcurrentDictionary<Guid, AsyncQueueBase<TItem>.AsyncQueueItem> |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
_logger
Default implementation of IAsyncQueueBase<TItem> base functionality
Declaration
protected readonly ILogger<AsyncQueueBase<TItem>> _logger
Field Value
| Type | Description |
|---|---|
| ILogger<AsyncQueueBase<TItem>> |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
_principalAccessor
Default implementation of IAsyncQueueBase<TItem> base functionality
Declaration
protected readonly INSPrincipalAccessor _principalAccessor
Field Value
| Type | Description |
|---|---|
| INSPrincipalAccessor |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
Properties
Count
Approximate count of items currently waiting in the queue (NOT including items currently being processed).
Declaration
public abstract 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
public abstract bool HasItemsInTheQueue { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
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
public abstract 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.
Enqueue(TItem)
Enqueue an item in the queue.
Declaration
public void Enqueue(TItem item)
Parameters
| Type | Name | Description |
|---|---|---|
| TItem | item |
Remarks
Information about current tenant and user is collected and stored with the item in the queue. This contextual settings are applied before the item is processed.
EnterQueueItemContext(AsyncQueueItem)
Default implementation of IAsyncQueueBase<TItem> base functionality
Declaration
protected IDisposable EnterQueueItemContext(AsyncQueueBase<TItem>.AsyncQueueItem queueItem)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncQueueBase<TItem>.AsyncQueueItem | queueItem |
Returns
| Type | Description |
|---|---|
| IDisposable |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
GetInnerQueueCompletionTasks()
Default implementation of IAsyncQueueBase<TItem> base functionality
Declaration
protected abstract IEnumerable<Task> GetInnerQueueCompletionTasks()
Returns
| Type | Description |
|---|---|
| IEnumerable<Task> |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
InnerEnqueue(AsyncQueueItem)
Default implementation of IAsyncQueueBase<TItem> base functionality
Declaration
protected abstract void InnerEnqueue(AsyncQueueBase<TItem>.AsyncQueueItem queItem)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncQueueBase<TItem>.AsyncQueueItem | queItem |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
ProcessItemsAsync(AsyncQueueProcessItemAsync<TItem>, CancellationToken)
Process items in the queue
Declaration
public 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 |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
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
public abstract Task ProcessNextItemAsync(AsyncQueueProcessItemAsync<TItem> processor, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncQueueProcessItemAsync<TItem> | processor | Processor responsible for processing each item in the queue |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
Requeue(IAsyncQueueProcessItemContext<TItem>)
Default implementation of IAsyncQueueBase<TItem> base functionality
Declaration
public void Requeue(IAsyncQueueProcessItemContext<TItem> context)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncQueueProcessItemContext<TItem> | context |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
SignalProcessingCanceled()
Default implementation of IAsyncQueueBase<TItem> base functionality
Declaration
protected void SignalProcessingCanceled()
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
ToArray(bool)
Get a snapshot of all the items in the queue
Declaration
public abstract TItem[] ToArray(bool includeItemsBeingProcessed)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | includeItemsBeingProcessed | Include items currently being processed in the snapshot |
Returns
| Type | Description |
|---|---|
| TItem[] |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
WaitForInFlightItemsAsync(CancellationToken)
Wait for items that are currently being processed (in-flight) to complete. Unlike WaitForItemsInQueueToBeProcessedAsync(CancellationToken), this does NOT wait for items still sitting in the queue.
Declaration
public Task WaitForInFlightItemsAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
Functionality used by the AsyncQueueProcessor<TItem> to process items in the queue.
WaitForItemsInQueueToBeProcessedAsync(CancellationToken)
Wait for all items currently in the queue or currently being processed to be processed.
Declaration
public 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. |