From 1a39eda55d34b1ab48c1fc4ef03445efd59e4aa4 Mon Sep 17 00:00:00 2001 From: Brian Giori Date: Wed, 16 Oct 2024 07:17:47 -0700 Subject: [PATCH] fix: persistent tracking queue poller (#131) --- packages/experiment-browser/src/integration/manager.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/experiment-browser/src/integration/manager.ts b/packages/experiment-browser/src/integration/manager.ts index 1205da1..9e18dd1 100644 --- a/packages/experiment-browser/src/integration/manager.ts +++ b/packages/experiment-browser/src/integration/manager.ts @@ -170,6 +170,7 @@ export class PersistentTrackingQueue { private readonly maxQueueSize: number; private readonly isLocalStorageAvailable = isLocalStorageAvailable(); private inMemoryQueue: ExperimentEvent[] = []; + private poller: any | undefined; private tracker: ((event: ExperimentEvent) => boolean) | undefined; constructor(instanceName: string, maxQueueSize: number = MAX_QUEUE_SIZE) { @@ -186,6 +187,9 @@ export class PersistentTrackingQueue { setTracker(tracker: (event: ExperimentEvent) => boolean): void { this.tracker = tracker; + this.poller = safeGlobal.setInterval(() => { + this.loadFlushStore(); + }, 1000); this.loadFlushStore(); } @@ -196,6 +200,10 @@ export class PersistentTrackingQueue { if (!this.tracker(event)) return; } this.inMemoryQueue = []; + if (this.poller) { + safeGlobal.clearInterval(this.poller); + this.poller = undefined; + } } private loadQueue(): void {