From d9e9deea514316ff2823e7669d68ea6844868930 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 7 Jun 2022 16:58:28 -0400 Subject: [PATCH] Simplify OperationBatcher queue consumption scheduling. Quick follow-up to PR #9793. --- src/link/batch/batching.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/link/batch/batching.ts b/src/link/batch/batching.ts index 296f9ecaa30..6edee97624c 100644 --- a/src/link/batch/batching.ts +++ b/src/link/batch/batching.ts @@ -101,10 +101,7 @@ export class OperationBatcher { } // The first enqueued request triggers the queue consumption after `batchInterval` milliseconds. - if (isFirstEnqueuedRequest) { - this.scheduleQueueConsumption(key); - } else if (this.batchDebounce) { - clearTimeout(this.scheduledBatchTimer); + if (isFirstEnqueuedRequest || this.batchDebounce) { this.scheduleQueueConsumption(key); } @@ -214,6 +211,7 @@ export class OperationBatcher { } private scheduleQueueConsumption(key: string): void { + clearTimeout(this.scheduledBatchTimer); this.scheduledBatchTimer = setTimeout(() => { this.consumeQueue(key); }, this.batchInterval);