diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-10 02:40:47 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-10 02:40:47 +0800 |
commit | 2e8f74abce7be3a5799bb93a0360d299de55b621 (patch) | |
tree | e052e2d4aeaf85546cde770748ebc5d2058ea109 /packages/instant/src/util/heartbeater.ts | |
parent | df91d343154bced69be86f7af4c4c702286cfd16 (diff) | |
download | dexon-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.ts | 12 |
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); } |