Class TaskCompletionPipe<T>
Represents a pipe to process asynchronous tasks as they complete.
Inherited Members
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 SourceTaskCompletionPipe()
Initializes a new pipe.
Declaration
public TaskCompletionPipe()
Properties
| Edit this page View SourceCompletion
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 | |
PendingTaskInterruptedException | Reset() was called before completion. |
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 SourceAdd(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. |
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 |
|
InvalidOperationException | The pipe is closed. |
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 |
|
InvalidOperationException | The pipe is closed. |
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. |
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. |
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.
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 |
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 |
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> |
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> |
Exceptions
Type | Condition |
---|---|
TimeoutException | The operation has timed out. |