Search code examples
c#.netconcurrencytpl-dataflow

"BatchBlock" does not work properly in non-greedy mode


When I use greedy mode, everything works as expected. But when I enable non-greedy mode, аt the moment of executing "foo.Receive()", the thread hangs while waiting.

BatchBlock<int> foo = new(1, new()
{
    //Greedy = false
});

foo.Post(1);

Console.WriteLine(foo.Receive());

What am I doing wrong?

.NET version: 8.0.303, Windows 11


Solution

  • In case it helps someone in the future (I had to additionally use "BufferBlock")

    BufferBlock<int> buffer = new();
    buffer.Post(1);
    
    BatchBlock<int> foo = new(1, new()
    {
        Greedy = false
    });
    
    buffer.LinkTo(foo);
    
    Console.WriteLine(foo.Receive());