aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/heartbeater.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/instant/src/util/heartbeater.ts')
-rw-r--r--packages/instant/src/util/heartbeater.ts12
1 files changed, 9 insertions, 3 deletions
diff --git a/packages/instant/src/util/heartbeater.ts b/packages/instant/src/util/heartbeater.ts
index bb4e99383..87af48423 100644
--- a/packages/instant/src/util/heartbeater.ts
+++ b/packages/instant/src/util/heartbeater.ts
@@ -4,18 +4,24 @@ type HeartbeatableFunction = () => Promise<void>;
export class Heartbeater {
private _intervalId?: number;
private _hasPendingRequest: boolean;
+ private _performImmediatelyOnStart: boolean;
private _performFunction: HeartbeatableFunction;
- public constructor(_performingFunctionAsync: HeartbeatableFunction) {
- this._performFunction = _performingFunctionAsync;
+ public constructor(performingFunctionAsync: HeartbeatableFunction, performImmediatelyOnStart: boolean) {
+ this._performFunction = performingFunctionAsync;
this._hasPendingRequest = false;
+ this._performImmediatelyOnStart = performImmediatelyOnStart;
}
public start(intervalTimeMs: number): void {
if (!_.isUndefined(this._intervalId)) {
throw new Error('Heartbeat is running, please stop before restarting');
}
- this._trackAndPerformAsync();
+
+ if (this._performImmediatelyOnStart) {
+ this._trackAndPerformAsync();
+ }
+
this._intervalId = window.setInterval(this._trackAndPerformAsync.bind(this), intervalTimeMs);
}