aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/heartbeater.ts
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-10 02:40:47 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-10 02:40:47 +0800
commit2e8f74abce7be3a5799bb93a0360d299de55b621 (patch)
treee052e2d4aeaf85546cde770748ebc5d2058ea109 /packages/instant/src/util/heartbeater.ts
parentdf91d343154bced69be86f7af4c4c702286cfd16 (diff)
downloaddexon-sol-tools-2e8f74abce7be3a5799bb93a0360d299de55b621.tar
dexon-sol-tools-2e8f74abce7be3a5799bb93a0360d299de55b621.tar.gz
dexon-sol-tools-2e8f74abce7be3a5799bb93a0360d299de55b621.tar.bz2
dexon-sol-tools-2e8f74abce7be3a5799bb93a0360d299de55b621.tar.lz
dexon-sol-tools-2e8f74abce7be3a5799bb93a0360d299de55b621.tar.xz
dexon-sol-tools-2e8f74abce7be3a5799bb93a0360d299de55b621.tar.zst
dexon-sol-tools-2e8f74abce7be3a5799bb93a0360d299de55b621.zip
Use existing functions instead of writing our own
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);
}