ChannelUtils/Extensions.cs
/// <summary>
/// Flattens the sequences from input channel into one sequence into resulting channel
/// </summary>
/// <param name="data"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
Flattens the sequences from input channel into one sequence into resulting channel
Flattens the sequences from input channel into one sequence into resulting channel
public static ChannelReader<T> Flatten<T>(this ChannelReader<IEnumerable<T>> data)
		{
			var ch = Channel.CreateUnbounded<T>(new UnboundedChannelOptions
			{
				AllowSynchronousContinuations = true
			});
			Task.Run(async () =>
			{
				while (await data.WaitToReadAsync())
				{
					if (!data.TryRead(out var channelData)) continue;
					foreach (var i in channelData)
					{
						await ch.Writer.WriteAsync(i);
					}
				}
				ch.Writer.Complete();
			});
			return ch.Reader;
		}
public static ChannelReader < T > Flatten < T > ( this ChannelReader < IEnumerable < T > > data ) { var ch = Channel . CreateUnbounded < T > ( new UnboundedChannelOptions { AllowSynchronousContinuations = true } ) ; Task . Run ( async ( ) => { while ( await data . WaitToReadAsync ( ) ) { if ( ! data . TryRead ( out var channelData ) ) continue ; foreach ( var i in channelData ) { await ch . Writer . WriteAsync ( i ) ; } } ch . Writer . Complete ( ) ; } ) ; return ch . Reader ; }
Flattens the sequences from input channel into one sequence into resulting channel
Flattens the sequences from input channel into one sequence into resulting channel
None
ChannelReader<IEnumerable<T>>
this
data
None
typeparam
None