Skip to content

Commit 26120e5

Browse files
committed
prevent creating zombie intervals on reset
1 parent 049d104 commit 26120e5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/core/src/v3/utils/interval.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class IntervalService {
1313
private _nextInterval: NodeJS.Timeout | undefined;
1414
private _leadingEdge: boolean;
1515
private _isEnabled: boolean;
16+
private _isExecuting: boolean;
1617

1718
constructor(opts: IntervalServiceOptions) {
1819
this._onInterval = opts.onInterval;
@@ -22,6 +23,7 @@ export class IntervalService {
2223
this._nextInterval = undefined;
2324
this._leadingEdge = opts.leadingEdge ?? false;
2425
this._isEnabled = false;
26+
this._isExecuting = false;
2527
}
2628

2729
start() {
@@ -52,6 +54,10 @@ export class IntervalService {
5254
return;
5355
}
5456

57+
if (this._isExecuting) {
58+
return;
59+
}
60+
5561
this.#clearNextInterval();
5662
this.#scheduleNextInterval();
5763
}
@@ -72,6 +78,13 @@ export class IntervalService {
7278
return;
7379
}
7480

81+
if (this._isExecuting) {
82+
console.error("Interval handler already running, skipping");
83+
return;
84+
}
85+
86+
this._isExecuting = true;
87+
7588
try {
7689
await this._onInterval();
7790
} catch (error) {
@@ -82,9 +95,10 @@ export class IntervalService {
8295
console.error("Error during interval error handler", error);
8396
}
8497
}
98+
} finally {
99+
this.#scheduleNextInterval();
100+
this._isExecuting = false;
85101
}
86-
87-
this.#scheduleNextInterval();
88102
};
89103

90104
#clearNextInterval() {

0 commit comments

Comments
 (0)