From 5dd89999a7625c999434016dbf3bd6d509d7417a Mon Sep 17 00:00:00 2001 From: Moumita <36885121+MoumitaM@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:44:08 +0530 Subject: [PATCH] fix: concurrent event triggering unnecessary flush call (#113) * fix: concurrent event triggering unnecessary flush call * chore: revert package.json changes * chore: refactor code --------- Co-authored-by: Moumita Mandal --- src/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.js b/src/index.js index a566811..af33ff8 100644 --- a/src/index.js +++ b/src/index.js @@ -621,6 +621,11 @@ class Analytics { } const items = this.queue.splice(0, this.flushAt); + // Do not proceed in case the items array is empty + if (items.length === 0) { + setImmediate(callback); + return Promise.resolve(); + } const callbacks = items.map((item) => item.callback); const messages = items.map((item) => { // if someone mangles directly with queue