@samitouri / QOSami-HFS / commits / e1329a0b

singleWorkerFromBatchWorker returning individually

Massimo Melina committed Jun 29, 2024 at 10:27 UTC e1329a0bd6bfb41c7511803e2c44b9266850a147
3 files changed +7 -7
dev-plugins.md
+1 -1
@@ -602,7 +602,7 @@ If you want to override a text regardless of the language, use the special langu
602
603 ## API version history
604
605 -- 8.89 (v0.53.0)
605 +- 8.891 (v0.53.0)
606 - api.openDb
607 - frontend event: menuZip
608 - config.type:username
src/const.ts
+1 -1
@@ -7,7 +7,7 @@ import { mkdirSync } from 'fs'
7 import { basename, dirname, join } from 'path'
8 export * from './cross-const'
9
10 -export const API_VERSION = 8.89
10 +export const API_VERSION = 8.891
11 export const COMPATIBLE_API_VERSION = 1 // while changes in the api are not breaking, this number stays the same, otherwise it is made equal to API_VERSION
12 export const HFS_REPO = 'rejetto/hfs'
13
src/debounceAsync.ts
+5 -5
@@ -84,15 +84,15 @@ export function debounceAsync<Cancelable extends boolean = false, A extends unkn
84 }
85
86 // given a function that works on a batch of requests, returns the function that works on a single request
87 -export function singleWorkerFromBatchWorker<Args extends any[]>(batchWorker: (batch: Args[]) => unknown) {
87 +export function singleWorkerFromBatchWorker<Args extends any[]>(batchWorker: (batch: Args[]) => unknown, { maxWait=Infinity }={}) {
88 let batch: Args[] = []
89 const debounced = debounceAsync(async () => {
90 const ret = batchWorker(batch)
91 - batch = []
91 + batch = [] // this is reset as batchWorker starts, but without waiting
92 return ret
93 - })
93 + }, 100, { maxWait })
94 return (...args: Args) => {
95 - batch.push(args)
96 - return debounced()
95 + const idx = batch.push(args) - 1
96 + return debounced().then((x: any) => x[idx])
97 }
98 }
\ No newline at end of file