using Sony.Filtr.Functional; using System; using System.Collections.Generic; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; namespace Sony.Filtr.Utility.Extensions { public static class TPLDataflowExtensions { public static BatchBlock Batch(this ISourceBlock sourceBlock, int batchSize, DataflowLinkOptions linkOptions) { var batchBlock = new BatchBlock(batchSize); sourceBlock.LinkTo(batchBlock, linkOptions); return batchBlock; } public static TransformManyBlock AsTransformManyBlock(this Func>> func, ExecutionDataflowBlockOptions blockOptions) { return new TransformManyBlock(func, blockOptions); } public static TransformManyBlock> AsTransformManyBlock(this Func>>> func, ExecutionDataflowBlockOptions blockOptions) { return new TransformManyBlock>(func, blockOptions); } public static TransformBlock AsTransformBlock(this Func> func, ExecutionDataflowBlockOptions blockOptions) { return new TransformBlock(func, blockOptions); } public static ActionBlock AsActionBlock(this Func> func, ExecutionDataflowBlockOptions blockOptions) { return new ActionBlock(func, blockOptions); } public static ActionBlock AsActionBlock(this Func>> func, ExecutionDataflowBlockOptions blockOptions) { return new ActionBlock(func, blockOptions); } public static TransformBlock ContinueWith( this ISourceBlock sourceBlock, Func> func, ExecutionDataflowBlockOptions blockOptions, DataflowLinkOptions linkOptions) { var transformBlock = new TransformBlock(func, blockOptions); sourceBlock.LinkTo(transformBlock, linkOptions); return transformBlock; } public static ActionBlock ContinueWith( this ISourceBlock sourceBlock, Func func, ExecutionDataflowBlockOptions blockOptions, DataflowLinkOptions linkOptions) { var actionBlock = new ActionBlock(func, blockOptions); sourceBlock.LinkTo(actionBlock, linkOptions); return actionBlock; } } }