CKTIS / C#
System.Collections.Generic.IAsyncEnumerable: referencia práctica
System.Collections.Generic.IAsyncEnumerable: referencia práctica: IAsyncEnumerable<T> representa un flujo cuyas operaciones MoveNextAsync sucesivas pueden esperar cada elemento de forma asíncrona.
Versión: .NET API; verified on .NET 10.0.14
Sintaxis
System.Collections.Generic.IAsyncEnumerable /* select a documented member or constructor */IAsyncEnumerable representa un flujo cuyas operaciones MoveNextAsync sucesivas pueden esperar cada elemento de forma asíncrona.
Úsalo para datos que llegan gradualmente y así procesar elementos sin almacenar en memoria todo el resultado.
Propaga la cancelación y libera el enumerador asíncrono mediante await foreach o await using.
Un origen puede ser de un solo uso, infinito o lanzar una excepción solo al alcanzar un elemento posterior.
El programa completo usa realmente System.Collections.Generic.IAsyncEnumerable; su stdout esperado exacto es 7.
Ejemplos
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
El programa completo usa realmente `System.Collections.Generic.IAsyncEnumerable`; su stdout esperado exacto es `7`.