CKTIS / C#
System.Collections.Generic.IAsyncEnumerable: referência prática
System.Collections.Generic.IAsyncEnumerable: referência prática: IAsyncEnumerable<T> representa um fluxo cujas operações MoveNextAsync sucessivas podem esperar assincronamente por cada elemento.
Versão: .NET API; verified on .NET 10.0.14
Sintaxe
System.Collections.Generic.IAsyncEnumerable /* select a documented member or constructor */IAsyncEnumerable representa um fluxo cujas operações MoveNextAsync sucessivas podem esperar assincronamente por cada elemento.
Usa-o para dados que chegam gradualmente, permitindo processar elementos sem guardar o resultado inteiro.
Propaga o cancelamento e liberta o enumerador assíncrono através de await foreach ou await using.
Uma origem pode ser de uso único, infinita ou lançar uma exceção apenas ao chegar a um elemento posterior.
O programa completo usa realmente System.Collections.Generic.IAsyncEnumerable; o stdout exato esperado é 7.
Exemplos
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; }
Resultado
7
O programa completo usa realmente `System.Collections.Generic.IAsyncEnumerable`; o stdout exato esperado é `7`.