コード例 #1
0
        /*
         * public static IMessagePipeline<TSource, IEnumerable<TDestination>> Batch<TSource, TDestination>(
         *  this IMessagePipeline<TSource, TDestination> pipeline,
         *  int size,
         *  int time = 0)
         * {
         *  if (size <= 1)
         *      throw new ArgumentException("Buffer size must be greater that 1");
         *
         *  var batch = new BatchBlock<TDestination>(size, new GroupingDataflowBlockOptions
         *  {
         *      EnsureOrdered = true,
         *      BoundedCapacity = size
         *  });
         *
         *  var timer = new Timer(_ => batch.TriggerBatch(), null, time, Timeout.Infinite);
         *
         *  var transform = new TransformBlock<TDestination[], TDestination[]>(x =>
         *      {
         *          timer.Change(time, Timeout.Infinite);
         *          return x;
         *      },
         *      new ExecutionDataflowBlockOptions
         *      {
         *          EnsureOrdered = true,
         *          BoundedCapacity = 1
         *      });
         *
         *  batch.LinkTo(transform);
         *
         *  return pipeline.Block(DataflowBlock.Encapsulate(batch, transform));
         * }*/

        public static IMessagePipeline <IMessage <T>, IMessageEnumerable <T> > Batch <T>(
            this IMessagePipeline <IMessage <T>, IMessage <T> > pipeline,
            int size,
            int time)
        {
            return(pipeline.Batch(size, TimeSpan.FromMilliseconds(time)));
        }