Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Created February 1, 2026 12:40
Show Gist options
  • Select an option

  • Save wullemsb/15c0773fe8850f040dba926189fb80b6 to your computer and use it in GitHub Desktop.

Select an option

Save wullemsb/15c0773fe8850f040dba926189fb80b6 to your computer and use it in GitHub Desktop.
var sourceBlock = new BufferBlock<string>();
var urgentBlock = new ActionBlock<string>(msg => Console.WriteLine($"URGENT: {msg}"));
var normalBlock = new ActionBlock<string>(msg => Console.WriteLine($"Normal: {msg}"));
var unhandledBlock = new ActionBlock<string>(msg => Console.WriteLine($"Unhandled: {msg}"));
// Specific conditions first
sourceBlock.LinkTo(urgentBlock, new DataflowLinkOptions { PropagateCompletion = true },
msg => msg.StartsWith("URGENT:"));
sourceBlock.LinkTo(normalBlock, new DataflowLinkOptions { PropagateCompletion = true },
msg => msg.StartsWith("INFO:"));
// Catch-all for everything else - no predicate
sourceBlock.LinkTo(unhandledBlock, new DataflowLinkOptions { PropagateCompletion = true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment