Table of Contents

Class TaskAwaiting

Namespace
Garyon.Extensions
Assembly
Garyon.dll

Provides functions for awaiting tasks.

public static class TaskAwaiting
Inheritance
TaskAwaiting
Inherited Members

Methods

WaitAll(IAsyncEnumerable<Task>)

Awaits enumeration of the entire IAsyncEnumerable<T> and awaits all tasks.

public static Task WaitAll(this IAsyncEnumerable<Task> tasks)

Parameters

tasks IAsyncEnumerable<Task>

The tasks to await. The collection will be enumerated.

Returns

Task

A Task that represents the operation of awaiting all tasks in the collection.

Remarks

The implementation uses the ToListAsync<T>(IAsyncEnumerable<T>) method to first ensure all the elements are enumerated, forcing all tasks to be initialized, if they haven't already been. If this behavior is undesirable, consider using the WaitAllIteratively(IAsyncEnumerable<Task>) method.

WaitAll(IEnumerable<Task>)

Awaits all tasks in the provided collection.

public static Task WaitAll(this IEnumerable<Task> tasks)

Parameters

tasks IEnumerable<Task>

The tasks to await. The collection will be enumerated.

Returns

Task

A Task that represents the operation of awaiting all tasks in the collection.

WaitAllIteratively(IAsyncEnumerable<Task>)

Awaits enumeration of the entire IAsyncEnumerable<T> and awaits all tasks.

public static Task WaitAllIteratively(this IAsyncEnumerable<Task> tasks)

Parameters

tasks IAsyncEnumerable<Task>

The tasks to await. The collection will be enumerated.

Returns

Task

A Task that represents the operation of awaiting all tasks in the collection.

Remarks

The implementation first awaits iteration to the next element in the IAsyncEnumerable<T> and then awaits the yielded Task, without guaranteeing that all tasks have been initialized and are simultaneously running on the background before their yielding. If this behavior is undesirable, consider using the WaitAll(IAsyncEnumerable<Task>) method.