DotNext.Threading by .NET Foundation and Contributors

<PackageReference Include="DotNext.Threading" Version="5.0.2" />

 TaskCompletionPipe<T>

public class TaskCompletionPipe<T> : IAsyncEnumerable<T>, IResettable where T : Task
Represents a pipe to process asynchronous tasks as they complete.

Initializes a new pipe.

public void Add(T task)

Adds the task to this pipe.

public void Add(T task, object userData)

Adds the task to this pipe.

public void Complete()

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

Gets the enumerator to get the completed tasks.

public void Reset()

Reuses the pipe.

public bool TryRead(out T task)

Attempts to read the completed task synchronously.

public bool TryRead(out T task, out object userData)

Attempts to read the completed task synchronously.

public ValueTask<bool> WaitToReadAsync(TimeSpan timeout, CancellationToken token = default)

Waits for the first completed task.

public ValueTask<bool> WaitToReadAsync(CancellationToken token = default)

Waits for the first completed task.