Show / Hide Table of Contents

Class TaskQueue<T>

Represents a queue of scheduled tasks.

Inheritance
object
TaskQueue<T>
Implements
IAsyncEnumerable<T>
IResettable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
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

capacity is less than or equal to zero.

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
| Edit this page View Source

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()
| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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

true if task is completed; otherwise, false.

| Edit this page View Source

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.

| Edit this page View Source

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.

Implements

IAsyncEnumerable<T>
IResettable

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
AsyncEnumerable.CopyAsync<T>(IAsyncEnumerable<T>, int, MemoryAllocator<T>?, CancellationToken)
AsyncEnumerable.ElementAtAsync<T>(IAsyncEnumerable<T>, int, CancellationToken)
AsyncEnumerable.FirstOrNoneAsync<T>(IAsyncEnumerable<T>, Predicate<T>, CancellationToken)
AsyncEnumerable.FirstOrNoneAsync<T>(IAsyncEnumerable<T>, CancellationToken)
AsyncEnumerable.ForEachAsync<T>(IAsyncEnumerable<T>, Action<T>, CancellationToken)
AsyncEnumerable.ForEachAsync<T>(IAsyncEnumerable<T>, Func<T, CancellationToken, ValueTask>, CancellationToken)
AsyncEnumerable.LastOrNoneAsync<T>(IAsyncEnumerable<T>, CancellationToken)
AsyncEnumerable.SkipNulls<T>(IAsyncEnumerable<T?>)
AsyncEnumerable.ToArrayAsync<T>(IAsyncEnumerable<T>, int, MemoryAllocator<T>?, CancellationToken)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾