Class TaskQueue<T>
+Represents a queue of scheduled tasks.
+Inherited Members
+ + + +Namespace: DotNext.Threading.Tasks
+Assembly: DotNext.Threading.dll
+Syntax
+public class TaskQueue<T> : IAsyncEnumerable<T>, IResettable where T : Task
+ Type Parameters
+Name | +Description | +
---|---|
T | +The type of tasks in the queue. + |
+
Remarks
+The queue returns tasks in the order as they added (FIFO) in contrast +to TaskCompletionPipe<T>.
+Constructors +
+ + | + Edit this page + + + View Source + + +TaskQueue(int)
+Initializes a new empty queue.
+Declaration
+public TaskQueue(int capacity)
+ Parameters
+Type | +Name | +Description | +
---|---|---|
int | +capacity | +The maximum number of tasks in the queue. + |
+
Exceptions
+Type | +Condition | +
---|---|
ArgumentOutOfRangeException | +
|
+
Properties +
+ + | + Edit this page + + + View Source + + +CanEnqueue
+Gets a value indicating that the queue has free space to place a task.
+Declaration
+public bool CanEnqueue { get; }
+ Property Value
+Type | +Description | +
---|---|
bool | ++ |
HeadTask
+Gets a head of this queue.
+Declaration
+public T? HeadTask { get; }
+ Property Value
+Type | +Description | +
---|---|
T | ++ |
Methods +
+ + | + Edit this page + + + View Source + + +Clear()
+Clears the queue.
+Declaration
+public void Clear()
+ DequeueAsync(CancellationToken)
+Dequeues the task asynchronously.
+Declaration
+public ValueTask<T> DequeueAsync(CancellationToken token = default)
+ Parameters
+Type | +Name | +Description | +
---|---|---|
CancellationToken | +token | +The token that can be used to cancel the operation. + |
+
Returns
+Type | +Description | +
---|---|
ValueTask<T> | +The completed task. + |
+
Remarks
+The caller suspends if the queue is empty.
+Exceptions
+Type | +Condition | +
---|---|
OperationCanceledException | +The operation has been canceled. + |
+
EnqueueAsync(T, CancellationToken)
+Enqueues the task.
+Declaration
+public ValueTask EnqueueAsync(T task, CancellationToken token = default)
+ Parameters
+Type | +Name | +Description | +
---|---|---|
T | +task | +The task to enqueue. + |
+
CancellationToken | +token | +The token that can be used to cancel the operation. + |
+
Returns
+Type | +Description | +
---|---|
ValueTask | ++ |
Remarks
+The caller suspends if the queue is full.
+Exceptions
+Type | +Condition | +
---|---|
OperationCanceledException | +The operation has been canceled. + |
+
EnsureFreeSpaceAsync(CancellationToken)
+Ensures that the queue has free space to enqueue a task.
+Declaration
+public ValueTask EnsureFreeSpaceAsync(CancellationToken token = default)
+ Parameters
+Type | +Name | +Description | +
---|---|---|
CancellationToken | +token | +The token that can be used to cancel the operation. + |
+
Returns
+Type | +Description | +
---|---|
ValueTask | +The task representing asynchronous execution of the operation. + |
+
Exceptions
+Type | +Condition | +
---|---|
OperationCanceledException | +The operation has been canceled. + |
+
GetAsyncEnumerator(CancellationToken)
+Gets consuming enumerator over tasks in the queue.
+Declaration
+public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken token)
+ Parameters
+Type | +Name | +Description | +
---|---|---|
CancellationToken | +token | +The token that can be used to cancel the operation. + |
+
Returns
+Type | +Description | +
---|---|
IAsyncEnumerator<T> | +The enumerator over completed tasks. + |
+
Remarks
+The enumerator stops if the queue is empty.
+TryDequeue(out T?)
+Tries to dequeue the completed task.
+Declaration
+public bool TryDequeue(out T? task)
+ Parameters
+Type | +Name | +Description | +
---|---|---|
T | +task | +The completed task. + |
+
Returns
+Type | +Description | +
---|---|
bool | ++ | +
TryDequeueAsync(CancellationToken)
+Tries to dequeue the completed task.
+Declaration
+public ValueTask<T?> TryDequeueAsync(CancellationToken token = default)
+ Parameters
+Type | +Name | +Description | +
---|---|---|
CancellationToken | +token | +The token that can be used to cancel the operation. + |
+
Returns
+Type | +Description | +
---|---|
ValueTask<T> | +The completed task; or null if the queue is empty. + |
+
Exceptions
+Type | +Condition | +
---|---|
OperationCanceledException | +The operation has been canceled. + |
+
TryEnqueue(T)
+Tries to enqueue the task.
+Declaration
+public bool TryEnqueue(T task)
+ Parameters
+Type | +Name | +Description | +
---|---|---|
T | +task | +The task to enqueue. + |
+
Returns
+Type | +Description | +
---|---|
bool | +true if the task is enqueued successfully; false if this queue is full. + |
+