-
Notifications
You must be signed in to change notification settings - Fork 94
Open
Description
In the example (shown below), the ChannelClosedException is caught when the channel is closed.
This is not an exception, but the rule.
Instead, the channel reader can also be used in combination with async streaming.
ProfessionalCSharp2021/2_Libs/Parallel/ParallelSamples/ChannelSample/ChannelSample.cs
Lines 26 to 44 in 5b29a81
public static Task ReadSomeDataAsync(ChannelReader<SomeData> reader) => | |
Task.Run(async () => | |
{ | |
try | |
{ | |
Console.WriteLine("Start reading..."); | |
Random r = new(); | |
while (true) | |
{ | |
await Task.Delay(r.Next(80)); | |
var data = await reader.ReadAsync(); | |
Console.WriteLine($"read: {data.Text}, available items: {reader.Count}"); | |
} | |
} | |
catch (ChannelClosedException) | |
{ | |
Console.WriteLine("channel closed"); | |
} | |
}); |
Metadata
Metadata
Assignees
Labels
No labels