fix: debounceAsync.flush() wasn't considering currently running invocations
Massimo Melina committed
Jun 9, 2022 at 17:42 UTC
ce0a6b51e8c4de6b9d6fb143ada7944e12aa9800
1 file changed
+1
-3
server/src/misc.ts
+1
-3
@@ -201,9 +201,7 @@ export function debounceAsync<CB extends (...args: any[]) => Promise<R>, R>(
201
const interceptingWrapper = (...args:any[]) => runningDebouncer = debouncer.apply(null, args)
202
return Object.assign(interceptingWrapper, {
203
cancel: () => whoIsWaiting = undefined,
204
- flush() {
205
- return whoIsWaiting ? callback.apply(null, whoIsWaiting) : this.cancel()
206
- },
204
+ flush: () => runningCallback ?? (whoIsWaiting && callback.apply(null, whoIsWaiting)),
205
})
206
207
async function debouncer(...args:any[]) {