예제 #1
0
 public LineAggregatorFlow() : base(DataflowOptions.Default)
 {
     this._lineProcessor = new TransformManyBlock <string, string>(line => line.Split(' ')).ToDataflow();
     this._aggregator    = new AggregatorFlow();
     this._lineProcessor.LinkTo(this._aggregator);
     this.RegisterChild(this._lineProcessor);
     this.RegisterChild(this._aggregator);
 }
예제 #2
0
        public static async Task FailDemoAsync()
        {
            var aggregatorFlow = new AggregatorFlow();

            aggregatorFlow.Post("a=1");
            aggregatorFlow.Post("b=2");
            aggregatorFlow.Post("a=5");
            aggregatorFlow.Post("a=badstring");
            aggregatorFlow.Complete();
            await aggregatorFlow.CompletionTask;
        }
예제 #3
0
        public static async Task CalcAsync()
        {
            var aggregatorFlow = new AggregatorFlow();

            aggregatorFlow.Post("a=1");
            aggregatorFlow.Post("b=2");
            aggregatorFlow.Post("a=5");
            aggregatorFlow.Complete();
            await aggregatorFlow.CompletionTask;

            Console.WriteLine("sum(a) = {0}", aggregatorFlow.Result["a"]); //prints sum(a) = 6


            //await aggregatorFlow.ProcessAsync(new[] { "a=1", "b=2", "a=5" }, completeFlowOnFinish: true);

            var lineAggregator = new LineAggregatorFlow();
            await lineAggregator.ProcessAsync(new[] { "a=1 b=2 a=5", "c=6 b=8" });

            Console.WriteLine("sum(a) = {0}", lineAggregator["a"]); //prints sum(a) = 6


            var intFlow = new ComplexIntFlow();
            await intFlow.ProcessAsync(new[] { 1, 2, 3 });
        }