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

Commit 3fbcb3c

Browse files
authored
Merge pull request #172 from chris-pardy/fix-timer-bug
Don't start a timer
2 parents b13490a + cdc7f27 commit 3fbcb3c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ class Analytics {
219219
const hasReachedQueueSize = this.queue.reduce((acc, item) => acc + JSON.stringify(item).length, 0) >= this.maxQueueSize
220220
if (hasReachedFlushAt || hasReachedQueueSize) {
221221
this.flush(callback)
222+
return
222223
}
223224

224225
if (this.flushInterval && !this.timer) {

test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,22 @@ test('enqueue - don\'t reset an existing timer', async t => {
267267
t.true(client.flush.calledOnce)
268268
})
269269

270+
test('enqueue - prevent flushing through time interval when already flushed by flushAt', async t => {
271+
const client = createClient({ flushAt: 2, flushInterval: 10 })
272+
client.flushed = false
273+
spy(client, 'flush')
274+
275+
client.enqueue('type', {})
276+
t.true(client.flush.calledOnce)
277+
278+
client.enqueue('type', {})
279+
client.enqueue('type', {})
280+
t.true(client.flush.calledTwice)
281+
282+
await delay(10)
283+
t.true(client.flush.calledTwice)
284+
})
285+
270286
test('enqueue - extend context', t => {
271287
const client = createClient()
272288

0 commit comments

Comments
 (0)