CKTIS / C#
System.Collections.Generic.IAsyncEnumerable: practical reference
System.Collections.Generic.IAsyncEnumerable: practical reference: IAsyncEnumerable<T> represents a stream whose successive MoveNextAsync operations may wait asynchronously for each item.
Version: .NET API; verified on .NET 10.0.14
Syntax
System.Collections.Generic.IAsyncEnumerable /* select a documented member or constructor */IAsyncEnumerable represents a stream whose successive MoveNextAsync operations may wait asynchronously for each item.
Use it for incrementally arriving data so consumers can process elements without buffering the whole result.
Propagate cancellation and dispose the async enumerator through await foreach or await using.
A source can be single-use, infinite, or raise an exception only when asynchronous enumeration reaches a later item.
The complete program actually uses System.Collections.Generic.IAsyncEnumerable; its exact expected stdout is 7.
Examples
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
await foreach (var value in Values()) Console.WriteLine(value);
static async IAsyncEnumerable<int> Values() { yield return 7; await Task.CompletedTask; }
Result
7
The complete program actually uses `System.Collections.Generic.IAsyncEnumerable`; its exact expected stdout is `7`.