Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #172 from chris-pardy/fix-timer-bug
Browse files Browse the repository at this point in the history
Don't start a timer
  • Loading branch information
pooyaj committed Aug 18, 2021
2 parents b13490a + cdc7f27 commit 3fbcb3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -219,6 +219,7 @@ class Analytics {
const hasReachedQueueSize = this.queue.reduce((acc, item) => acc + JSON.stringify(item).length, 0) >= this.maxQueueSize
if (hasReachedFlushAt || hasReachedQueueSize) {
this.flush(callback)
return
}

if (this.flushInterval && !this.timer) {
Expand Down
16 changes: 16 additions & 0 deletions test.js
Expand Up @@ -267,6 +267,22 @@ test('enqueue - don\'t reset an existing timer', async t => {
t.true(client.flush.calledOnce)
})

test('enqueue - prevent flushing through time interval when already flushed by flushAt', async t => {
const client = createClient({ flushAt: 2, flushInterval: 10 })
client.flushed = false
spy(client, 'flush')

client.enqueue('type', {})
t.true(client.flush.calledOnce)

client.enqueue('type', {})
client.enqueue('type', {})
t.true(client.flush.calledTwice)

await delay(10)
t.true(client.flush.calledTwice)
})

test('enqueue - extend context', t => {
const client = createClient()

Expand Down

0 comments on commit 3fbcb3c

Please sign in to comment.