diff options
| author | Sam Wilkins <samwilkins333@gmail.com> | 2019-09-18 04:22:54 -0400 |
|---|---|---|
| committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-09-18 04:22:54 -0400 |
| commit | 960b5babede63780bf91ce8fe8658e8c41925ecb (patch) | |
| tree | 9a44d626751f2f0f0f914039dcc6d8f5b325f249 /src/client/northstar/utils/Extensions.ts | |
| parent | 3f6f0a878b15aa5c569a8b522d1b24915749498e (diff) | |
final batching expansion
Diffstat (limited to 'src/client/northstar/utils/Extensions.ts')
| -rw-r--r-- | src/client/northstar/utils/Extensions.ts | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/client/northstar/utils/Extensions.ts b/src/client/northstar/utils/Extensions.ts index 65af7ea87..3722bfd52 100644 --- a/src/client/northstar/utils/Extensions.ts +++ b/src/client/northstar/utils/Extensions.ts @@ -23,7 +23,6 @@ String.prototype.Truncate = function (length: number, replacement: string): Stri interface BatchContext { completedBatches: number; remainingBatches: number; - isFullBatch: boolean; } type BatchConverterSync<I, O> = (batch: I[], context: BatchContext) => O[]; type BatchHandlerSync<I> = (batch: I[], context: BatchContext) => void; @@ -31,20 +30,43 @@ type BatchConverterAsync<I, O> = (batch: I[], context: BatchContext) => Promise< type BatchHandlerAsync<I> = (batch: I[], context: BatchContext) => Promise<void>; type BatchConverter<I, O> = BatchConverterSync<I, O> | BatchConverterAsync<I, O>; type BatchHandler<I> = BatchHandlerSync<I> | BatchHandlerAsync<I>; -type Batcher<I, A> = number | ((element: I, accumulator: A) => boolean | Promise<boolean>); +type FixedBatcher = { batchSize: number } | { batchCount: number, mode?: Mode }; +interface PredicateBatcher<I, A> { + executor: (element: I, accumulator: A | undefined) => A | undefined; + initial: A; +} +interface PredicateBatcherAsync<I, A> { + executor: (element: I, accumulator: A | undefined) => Promise<A | undefined>; + initial: A; +} +type Batcher<I, A> = FixedBatcher | PredicateBatcher<I, A>; +type BatcherAsync<I, A> = Batcher<I, A> | PredicateBatcherAsync<I, A>; interface Array<T> { - batch(batchSize: undefined): T[][]; + fixedBatch<T>(batcher: FixedBatcher): T[][]; + predicateBatch<T, A = undefined>(batcher: PredicateBatcher<T, A>): T[][]; + predicateBatchAsync<T, A = undefined>(batcher: PredicateBatcherAsync<T, A>): Promise<T[][]>; + batch<A = undefined>(batcher: Batcher<T, A>): T[][]; + batchAsync<A = undefined>(batcher: BatcherAsync<T, A>): Promise<T[][]>; + batchedForEach<A = undefined>(batcher: Batcher<T, A>, handler: BatchHandlerSync<T>): void; batchedMap<O, A = undefined>(batcher: Batcher<T, A>, handler: BatchConverterSync<T, O>): O[]; + batchedForEachAsync<A = undefined>(batcher: Batcher<T, A>, handler: BatchHandler<T>): Promise<void>; batchedMapAsync<O, A = undefined>(batcher: Batcher<T, A>, handler: BatchConverter<T, O>): Promise<O[]>; + batchedForEachInterval<A = undefined>(batcher: Batcher<T, A>, handler: BatchHandler<T>, interval: number): Promise<void>; batchedMapInterval<O, A = undefined>(batcher: Batcher<T, A>, handler: BatchConverter<T, O>, interval: number): Promise<O[]>; + lastElement(): T; } +Array.prototype.fixedBatch = extensions.FixedBatch; +Array.prototype.predicateBatch = extensions.PredicateBatch; +Array.prototype.predicateBatchAsync = extensions.PredicateBatchAsync; Array.prototype.batch = extensions.Batch; +Array.prototype.batchAsync = extensions.BatchAsync; + Array.prototype.batchedForEach = extensions.ExecuteInBatches; Array.prototype.batchedMap = extensions.ConvertInBatches; Array.prototype.batchedForEachAsync = extensions.ExecuteInBatchesAsync; |
