public static BlockContainer <TIn, TOut> AutoComplete <TIn, TOut>(this BlockContainer <TIn, TOut> blockContainer, TimeSpan timeout) where TIn : ITracableItem where TOut : ITracableItem { var autoCompletePair = new AutoCompleteContainerPair <TIn, TOut>(timeout); var merged = new BlockContainerMerger <TIn, TIn, TOut, TOut>( autoCompletePair.Before, blockContainer, autoCompletePair.After); return(merged); }
public async Task TestAutoComplete1() { var block1 = new TransformManyBlock <Int, Int>(i => { return(new [] { i }); //preserve the guid }); var block2 = new TransformManyBlock <Int, Int>(i => { int j = i.Val + 1; Console.WriteLine("block2: i = {0}, j = {1}", i.Val, j); Thread.Sleep(500); if (j < 10) { return new[] { new Int { Val = j } } } ; else { return(Enumerable.Empty <Int>()); } }); var container1 = BlockContainerUtils.FromBlock(block1); var container2 = BlockContainerUtils.FromBlock(block2); var pair = new AutoCompleteContainerPair <Int, Int>(TimeSpan.FromSeconds(1)); container1.LinkTo(pair.Before); pair.Before.LinkTo(container2); container2.LinkTo(pair.After); pair.After.LinkTo(container1); container1.InputBlock.Post(new Int() { Val = 1 }); Assert.IsTrue(await container2.CompletionTask.FinishesIn(TimeSpan.FromSeconds(10))); }