From 4c4587ca4c5a609980685cb9f694addd4ab53609 Mon Sep 17 00:00:00 2001 From: Dobes Vandermeer Date: Thu, 20 Aug 2020 14:03:11 -0700 Subject: [PATCH 1/2] Add flush method to Batcher --- src/Batcher.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Batcher.coffee b/src/Batcher.coffee index 5ddd66d..510c5fa 100644 --- a/src/Batcher.coffee +++ b/src/Batcher.coffee @@ -35,5 +35,9 @@ class Batcher @_flush() , @maxTime ret + + flush: -> + if @_arr.length + @_flush() module.exports = Batcher From 7f53608bb918529facfc9ab96e76a59b5be78b92 Mon Sep 17 00:00:00 2001 From: Dobes Vandermeer Date: Thu, 20 Aug 2020 14:11:08 -0700 Subject: [PATCH 2/2] Add Batcher.flush to types files --- bottleneck.d.ts | 7 ++++++- bottleneck_types.ejs | 5 +++++ src/Batcher.coffee | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) 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 510c5fa..65599b7 100644 --- a/src/Batcher.coffee +++ b/src/Batcher.coffee @@ -35,7 +35,7 @@ class Batcher @_flush() , @maxTime ret - + flush: -> if @_arr.length @_flush()