Skip to content

Commit a0b021f

Browse files
(event publisher) use setTimeout instead of setInterval
Signed-off-by: Thomas Poignant <[email protected]>
1 parent 96f0404 commit a0b021f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

libs/providers/go-feature-flag/src/lib/service/event-publisher.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,19 @@ export class EventPublisher {
4949
return;
5050
}
5151
this.isRunning = true;
52-
const flushInterval = this.options.dataFlushInterval || DEFAULT_FLUSH_INTERVAL_MS;
53-
this.intervalId = setInterval(async () => {
54-
await this.publishEvents();
55-
}, flushInterval);
52+
this.runPublisher();
53+
}
54+
55+
/**
56+
* Runs the publisher and sets up a periodic runner.
57+
* @returns {Promise<void>} A promise that resolves when the publisher has run.
58+
*/
59+
private async runPublisher(): Promise<void> {
60+
await this.publishEvents();
61+
if (this.isRunning) {
62+
const flushInterval = this.options.dataFlushInterval || DEFAULT_FLUSH_INTERVAL_MS;
63+
this.intervalId = setTimeout(() => this.runPublisher(), flushInterval);
64+
}
5665
}
5766

5867
/**

0 commit comments

Comments
 (0)