diff --git a/bottleneck.d.ts b/bottleneck.d.ts index 00c24cb..eba8dd2 100644 --- a/bottleneck.d.ts +++ b/bottleneck.d.ts @@ -298,9 +298,14 @@ declare module "bottleneck" { * Add a request to the Batcher. Batches are flushed to the "batch" event. */ add(data: any): Promise; + + /** + * Force a 'batch' event if there are any rows currently in the batch + */ + flush(): void; } - class Group { + class Group { constructor(options?: Bottleneck.ConstructorOptions); id: string; diff --git a/bottleneck_types.ejs b/bottleneck_types.ejs index ac79560..ac7d365 100644 --- a/bottleneck_types.ejs +++ b/bottleneck_types.ejs @@ -297,6 +297,11 @@ namespace Bottleneck { * Add a request to the Batcher. Batches are flushed to the "batch" event. */ add(data: any): Promise; + + /** + * Force a 'batch' event if there are any rows currently in the batch + */ + flush(): void; } class Group { diff --git a/src/Batcher.coffee b/src/Batcher.coffee index 5ddd66d..65599b7 100644 --- a/src/Batcher.coffee +++ b/src/Batcher.coffee @@ -36,4 +36,8 @@ class Batcher , @maxTime ret + flush: -> + if @_arr.length + @_flush() + module.exports = Batcher