Skip to content

Commit

Permalink
fix: persistent tracking queue poller (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori authored Oct 16, 2024
1 parent 93532c1 commit 1a39eda
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/experiment-browser/src/integration/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}

Expand All @@ -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 {
Expand Down

0 comments on commit 1a39eda

Please sign in to comment.