TaskAsyncEnumerableExtensions.ToBlockingEnumerable<T> Method

Definition

Converts an IAsyncEnumerable<T> instance into an IEnumerable<T> that enumerates elements in a blocking manner.

C#
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.Collections.Generic.IEnumerable<T> ToBlockingEnumerable<T>(this System.Collections.Generic.IAsyncEnumerable<T> source, System.Threading.CancellationToken cancellationToken = default);

Type Parameters

T

The type of the objects being iterated.

Parameters

source
IAsyncEnumerable<T>

The source enumerable being iterated.

cancellationToken
CancellationToken

The CancellationToken to use.

Returns

An IEnumerable<T> instance that enumerates the source IAsyncEnumerable<T> in a blocking manner.

Attributes

Remarks

This method is implemented by using deferred execution. The underlying IAsyncEnumerable<T> will not be enumerated unless the returned IEnumerable<T> is enumerated by calling its GetEnumerator() method. Async enumeration does not happen in the background; each MoveNext call will invoke the underlying MoveNextAsync() exactly once.

Applies to

Производ Верзије
.NET 7, 8, 9, 10