コード例 #1
0
 public static IAsyncExecutor <TInput, TOutput> Create <TInput, TOutput>(
     [NotNull] BatchPolicy batchPolicy,
     Func <IEnumerable <TInput>, Task <IList <TOutput> > > batchedItemsMethod,
     OutputToInputMatchFunction.Delegate <TInput, TOutput> ouputToInputMatchFunction)
 {
     return(new BatchExecutor <TInput, TOutput>(
                batchPolicy,
                batchedItemsMethod,
                ouputToInputMatchFunction));
 }
コード例 #2
0
 public BatchExecutor(
     [NotNull] BatchPolicy batchPolicy,
     Func <IEnumerable <TInput>, Task <IList <TOutput> > > batchedItemsMethod,
     OutputToInputMatchFunction.Delegate <TInput, TOutput> ouputToInputMatchFunction)
     : this(
         batchPolicy,
         null,
         batchedItemsMethod,
         ouputToInputMatchFunction)
 {
 }
コード例 #3
0
        public BatchExecutor(
            [NotNull] BatchPolicy batchPolicy,
            Func <TInput, Task <TOutput> > singleItemMethod,
            // IList b/c OutputMatchFunction.OutputOrderMatchesInputOrder presumes we got it in order, and want the data type to specify that rather than implicit assumption
            Func <IEnumerable <TInput>, Task <IList <TOutput> > > batchedItemsMethod,
            OutputToInputMatchFunction.Delegate <TInput, TOutput> ouputToInputMatchFunction)
        {
            this._batchPolicy               = batchPolicy;
            this._singleItemMethod          = singleItemMethod;
            this._batchedItemsMethod        = batchedItemsMethod;
            this._ouputToInputMatchFunction = ouputToInputMatchFunction;

            this.cts = new CancellationTokenSource();

            this.incomingWork = new Subject <UnitOfWork>();
            this.subscription = this.incomingWork
                                .Buffer(batchPolicy.MaxAge, batchPolicy.MaxBatchSize)
                                .Subscribe(this.ProcessBatch);
        }