Show / Hide Table of Contents

Class TaskCompletionPipe<T>

Represents a pipe to process asynchronous tasks as they complete.

Inheritance
object
TaskCompletionPipe<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 TaskCompletionPipe<T> : IAsyncEnumerable<T>, IResettable where T : Task
Type Parameters
Name Description
T

The type of the task.

Constructors

| Edit this page View Source

TaskCompletionPipe()

Initializes a new pipe.

Declaration
public TaskCompletionPipe()

Properties

| Edit this page View Source

Completion

Gets a task that turns into completed state when all submitted tasks are completed.

Declaration
public Task Completion { get; }
Property Value
Type Description
Task
Exceptions
Type Condition
NotSupportedException

IsCompletionTaskSupported is false.

PendingTaskInterruptedException

Reset() was called before completion.

| Edit this page View Source

IsCompletionTaskSupported

Gets or sets a value indicating that this pipe supports Completion property.

Declaration
public bool IsCompletionTaskSupported { get; init; }
Property Value
Type Description
bool

Methods

| Edit this page View Source

Add(ReadOnlySpan<T>, bool, object?)

Submits a group of tasks and mark this pipe as completed.

Declaration
public void Add(ReadOnlySpan<T> tasks, bool complete = false, object? userData = null)
Parameters
Type Name Description
ReadOnlySpan<T> tasks

A group of tasks.

bool complete

true to submit tasks and complete the pipe; false to submit tasks.

object userData

Arbitrary object associated with the tasks.

Exceptions
Type Condition
InvalidOperationException

The pipe is closed.

| Edit this page View Source

Add(T)

Adds the task to this pipe.

Declaration
public void Add(T task)
Parameters
Type Name Description
T task

The task to add.

Exceptions
Type Condition
ArgumentNullException

task is null.

InvalidOperationException

The pipe is closed.

| Edit this page View Source

Add(T, object?)

Adds the task to this pipe.

Declaration
public void Add(T task, object? userData)
Parameters
Type Name Description
T task

The task to add.

object userData

Arbitrary object associated with the task.

Remarks

userData can be requested later using TryRead(out T?, out object?) method.

Exceptions
Type Condition
ArgumentNullException

task is null.

InvalidOperationException

The pipe is closed.

| Edit this page View Source

Complete()

Marks the pipe as being complete, meaning no more items will be added to it.

Declaration
public void Complete()
Exceptions
Type Condition
InvalidOperationException

The pipe is already completed.

| Edit this page View Source

GetAsyncEnumerator(CancellationToken)

Gets the enumerator to get the completed tasks.

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.

| Edit this page View Source

Reset()

Reuses the pipe.

Declaration
public void Reset()
Remarks

The pipe can be reused only if there are no active consumers and producers. Otherwise, the behavior of the pipe is unspecified.

| Edit this page View Source

TryRead(out T?)

Attempts to read the completed task synchronously.

Declaration
public bool TryRead(out T? task)
Parameters
Type Name Description
T task

The completed task.

Returns
Type Description
bool

true if a task was read; otherwise, false.

| Edit this page View Source

TryRead(out T?, out object?)

Attempts to read the completed task synchronously.

Declaration
public bool TryRead(out T? task, out object? userData)
Parameters
Type Name Description
T task

The completed task.

object userData

Arbitrary object associated with the task when it was added to the pipe.

Returns
Type Description
bool

true if a task was read; otherwise, false.

| Edit this page View Source

WaitToReadAsync(CancellationToken)

Waits for the first completed task.

Declaration
public ValueTask<bool> WaitToReadAsync(CancellationToken token = default)
Parameters
Type Name Description
CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<bool>

true if data is available to read; otherwise, false.

| Edit this page View Source

WaitToReadAsync(TimeSpan, CancellationToken)

Waits for the first completed task.

Declaration
public ValueTask<bool> WaitToReadAsync(TimeSpan timeout, CancellationToken token = default)
Parameters
Type Name Description
TimeSpan timeout

The time to wait for the task completion.

CancellationToken token

The token that can be used to cancel the operation.

Returns
Type Description
ValueTask<bool>

true if data is available to read; otherwise, false.

Exceptions
Type Condition
TimeoutException

The operation has timed out.

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
☀
☾