And
This defines parallel workflow operations;

            Workflow<string>.Definition()
             .Do(a => { Console.WriteLine("T1"); return ""; })
             .And.Do(a => { Console.Write("T2"); return ""; })
             .Then().Do(a => { Console.Write("T3"); return ""; });

In this example T1 and T2 execute in parallel, whereas T3 will always execute last.

Then() merging parallel operations back into the default sequential flow. This waits for all parallel operations to finish, therefore T3 will always be executed last. The following output is possible from the above snippet;

T1T2T3
T2T1T3

For brevity you dont have to have the And on subsequent calls. The And defines the start of the parallel block, whereas the Then() defines the end of the parallel block;

            Workflow<string>.Definition()
              .Do(a => { Console.WriteLine("T1"); return ""; })
             .And.Do(a => { Console.WriteLine("T2"); return ""; })
             .Do(a => { Console.WriteLine("T3"); return ""; })
             .Then().Do(a => { Console.WriteLine("T4"); return ""; });

In the above snippet, T1, T2 and T3 execute in parallel and is functionally equivelent to the (slightly) longer;

            Workflow<string>.Definition()
            .Do(a => { Console.WriteLine("T1"); return ""; })
             .And.Do(a => { Console.WriteLine("T2"); return ""; })
             And.Do(a => { Console.WriteLine("T3"); return ""; })
             .Then().Do(a => { Console.WriteLine("T4"); return ""; });

Parallel operations do not carry state between them. Typically you would use parallell execution to perform isolated tasks.

Last edited Jun 18, 2010 at 7:05 PM by djnz_gea, version 4

Comments

No comments yet.