What is the effect of PropigateCompletion on a BroadcastBlock

Отвечено What is the effect of PropigateCompletion on a BroadcastBlock

  • 22 апреля 2012 г. 6:12
     
     

    When I have a single TargetBlock linked to a BroadcastBlock, the PropigateCompletion tag seems to work as expected.

    However, when I attach 2 TargetBlocks it doesn't seem to to propigate correctly.



    Brad Serbu

Все ответы

  • 22 апреля 2012 г. 13:15
     
      С кодом

    It seems to work fine to me. You should post the code you're using, describe what it does and what you would expect it to do.

    In the following code, the completion propagates correctly to both targets for me:

    var buffer = new BufferBlock<int>();
    
    var target1 = new ActionBlock<int>(i => Console.WriteLine("Target 1: {0}", i));
    var target2 = new ActionBlock<int>(i => Console.WriteLine("Target 2: {0}", i));
    
    buffer.LinkTo(target1, new DataflowLinkOptions { PropagateCompletion = true });
    buffer.LinkTo(target2, new DataflowLinkOptions { PropagateCompletion = true });
    
    buffer.Post(1);
    buffer.Post(2);
    
    buffer.Complete();
    
    Task.WaitAll(target1.Completion, target2.Completion);
  • 22 апреля 2012 г. 16:59
     
     Отвечено

    It was my understanding of your code above that target2 would likely not get any messages, as target1 would greedly take all items.

    Changing your BufferBlock<T> to a BroadcastBloc<T, T> was what I was attempting.  In that case target2 does process messages, but it didn't seem to complete in my code.

    This was my fault and I found my bug.


    Brad Serbu