示例#1
0
 private async static void ProduceItems(PipelineSink <int> sink)
 {
     for (int i = 0; i < 10; i++)
     {
         await sink.Yield(i);
     }
 }
示例#2
0
        public static Incomplete <T> StartWith <T>(Action <PipelineSink <T> > sourceAction)
        {
            PipelineCoordinator coordinator = new PipelineCoordinator();
            PipelineSink <T>    sink        = new PipelineSink <T>(coordinator);

            coordinator.AddInitialAction(() => sourceAction(sink));
            return(new Incomplete <T>(sink, coordinator));
        }
示例#3
0
            public Incomplete <TResult> Then <TResult>(Action <PipelineSource <T>, PipelineSink <TResult> > connector)
            {
                PipelineSource <T> source = new PipelineSource <T>(coordinator);

                currentSink.AttachSource(source);
                PipelineSink <TResult> newSink = new PipelineSink <TResult>(coordinator);

                coordinator.AddInitialAction(() => connector(source, newSink));
                return(new Incomplete <TResult>(newSink, coordinator));
            }
示例#4
0
        private async static void TransformItems(PipelineSource <int> source, PipelineSink <string> sink)
        {
            Tuple <bool, int> current = await source.Receive();

            while (current.Item1)
            {
                await sink.Yield("Got " + current.Item2);

                current = await source.Receive();
            }
        }
示例#5
0
        private async static void FilterItems(PipelineSource <int> source, PipelineSink <int> sink)
        {
            Tuple <bool, int> current = await source.Receive();

            while (current.Item1)
            {
                int value = current.Item2;
                // Yield even numbers once, and multiples of 3 once (so 0 and 6 will be yielded twice each)
                if (value % 2 == 0)
                {
                    await sink.Yield(value);
                }
                if (value % 3 == 0)
                {
                    await sink.Yield(value);
                }
                current = await source.Receive();
            }
        }
示例#6
0
 internal Incomplete(PipelineSink <T> currentSink, PipelineCoordinator coordinator)
 {
     this.currentSink = currentSink;
     this.coordinator = coordinator;
 }