Created
February 1, 2026 12:39
-
-
Save wullemsb/3e3445cf1ba4d86caa81f5e61ea663a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Threading.Tasks.Dataflow; | |
| var broadcastBlock = new BroadcastBlock<int>(null); | |
| var evenBlock = new ActionBlock<int>(n => | |
| Console.WriteLine($"Even: {n}")); | |
| var oddBlock = new ActionBlock<int>(n => | |
| Console.WriteLine($"Odd: {n}")); | |
| // Link with predicates | |
| broadcastBlock.LinkTo(evenBlock, new DataflowLinkOptions { PropagateCompletion = true }, | |
| n => n % 2 == 0); | |
| broadcastBlock.LinkTo(oddBlock, new DataflowLinkOptions { PropagateCompletion = true }, | |
| n => n % 2 != 0); | |
| // Post some numbers | |
| for (int i = 0; i < 10; i++) | |
| { | |
| broadcastBlock.Post(i); | |
| } | |
| broadcastBlock.Complete(); | |
| await Task.WhenAll(evenBlock.Completion, oddBlock.Completion); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment