Skip to content

Commit

Permalink
fix: concurrent event triggering unnecessary flush call (#113)
Browse files Browse the repository at this point in the history
* fix: concurrent event triggering unnecessary flush call

* chore: revert package.json changes

* chore: refactor code

---------

Co-authored-by: Moumita Mandal <moumita@Moumitas-MacBook-Pro-2.local>
  • Loading branch information
MoumitaM and Moumita Mandal authored Aug 28, 2023
1 parent 3619247 commit 5dd8999
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5dd8999

Please sign in to comment.