Skip to content

Commit 96f0404

Browse files
use setTimeout instead of setInterval
Signed-off-by: Thomas Poignant <[email protected]>
1 parent 94c9a10 commit 96f0404

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

libs/providers/go-feature-flag/src/lib/evaluator/inprocess-evaluator.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,24 @@ export class InProcessEvaluator implements IEvaluator {
6969
await this.loadConfiguration(true);
7070
// Start periodic configuration polling
7171
if (this.options.flagChangePollingIntervalMs && this.options.flagChangePollingIntervalMs > 0) {
72-
this.periodicRunner = setInterval(
73-
() =>
74-
this.loadConfiguration(false).catch((error) => this.logger?.error('Failed to load configuration:', error)),
75-
this.options.flagChangePollingIntervalMs,
76-
);
72+
this.periodicRunner = setTimeout(() => this.poll(), this.options.flagChangePollingIntervalMs);
7773
}
7874
}
7975

76+
/**
77+
* Poll the configuration from the API.
78+
*/
79+
private poll(): void {
80+
this.loadConfiguration(false)
81+
.catch((error) => this.logger?.error('Failed to load configuration:', error))
82+
.finally(() => {
83+
if (this.periodicRunner) {
84+
// check if polling is still active
85+
this.periodicRunner = setTimeout(() => this.poll(), this.options.flagChangePollingIntervalMs);
86+
}
87+
});
88+
}
89+
8090
/**
8191
* Evaluates a boolean flag.
8292
* @param flagKey - The key of the flag to evaluate.

0 commit comments

Comments
 (0)