Pattern: Pipeline

Topics: Samples and Patterns
Coordinator
Jan 12, 2007 at 1:33 AM

private static void PipelineTest()
{
// Create 3 port-based "services" that each do their own processing and pipeline on to next service.
Port<int> service1Port = new Port<int>();
Port<int> service2Port = new Port<int>();
Port<int> service3Port = new Port<int>();

// Define our services.
// We could just as easy use a service class for each, but this shows the concept clearly.
Selector.SelectOne(true, service1Port,
delegate(int num)
{
num += 1;
service2Port.Push(num);
}).Run();
Selector.SelectOne(true, service2Port,
delegate(int num)
{
num += 1;
service3Port.Push(num);
}).Run();
Selector.SelectOne(true, service3Port,
delegate(int num)
{
num += 1;
Console.WriteLine("Result:{0}", num);
if (num < 10)
service1Port.Push(num); // Post back to start of pipeline.
}).Run();

// Push some data at start of pipeline.
service1Port.Push(1);
Console.WriteLine("Pipeline results:");
}