Joining flows

You can split a flow up into two branches - and you can join two (sub)flows (back) into one:

fig7.gif

This is done with a Join<>() following a Fork<>() or a fork´s Do<>():

var flow = new ForkedFlow<int, string, bool>(...)
    .Join<double>((s,b,pd)=>...);

The int arriving at the forking stage is split into a string branch and a bool branch. Those branches are immediately join together again into a double output. This doesn´t make much sense ;-) - but it should make clear how a join works.

The handler you pass to Join<>() expects two values - one from each branch to be joined - and a single output port. Its signature is:

Action<InputType0, InputType1, Port<OutputType>>

Once you´ve joined up branches you can continue with the main flow. Here´s an abbreviated version of a flow (no types, no handlers):

Flow
  .Do
  .Do
  .Fork
    .Do(
       Flow.Do.Do.Do,
       Flow.Do.Fork
               .Do(
                    Flow.Do,
                    Flow.Do.Do
                    )
               .Join
               .Do
       )
  .Join
  .Do
  .Fork
    .Do(
       Flow.Do.Do.Do,
       Flow.Do    
      )
  .Join
  .Do

It´s the pseudo-code implementation of

fig8.gif

Now remember: the data flows through such a graph sequentially. It´s a FIFO (unless you use Scatter<>()). But at each stage the CCR gets the chance to schedule another stage to run on a CPU core. That way many such flows can be processed concurrently.

Last edited Jul 3, 2009 at 8:47 PM by ralfw, version 4

Comments

No comments yet.