diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-07 00:22:28 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-07 00:22:28 +0800 |
commit | 88791f732fc83bb273508ec8d4b1e87c6bea05dc (patch) | |
tree | 6f1bf2e6b8c01fb4e4a22aedbc57c7e182faee68 /src/utils | |
parent | b1feb5ac29bf2dbe424a5485eb3e48e90c08ba94 (diff) | |
download | dexon-sol-tools-88791f732fc83bb273508ec8d4b1e87c6bea05dc.tar dexon-sol-tools-88791f732fc83bb273508ec8d4b1e87c6bea05dc.tar.gz dexon-sol-tools-88791f732fc83bb273508ec8d4b1e87c6bea05dc.tar.bz2 dexon-sol-tools-88791f732fc83bb273508ec8d4b1e87c6bea05dc.tar.lz dexon-sol-tools-88791f732fc83bb273508ec8d4b1e87c6bea05dc.tar.xz dexon-sol-tools-88791f732fc83bb273508ec8d4b1e87c6bea05dc.tar.zst dexon-sol-tools-88791f732fc83bb273508ec8d4b1e87c6bea05dc.zip |
Make intervalUtils an object instead of a class and make instance variable local
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/interval_utils.ts | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/utils/interval_utils.ts b/src/utils/interval_utils.ts index 6bcf5a643..1656318e6 100644 --- a/src/utils/interval_utils.ts +++ b/src/utils/interval_utils.ts @@ -1,20 +1,20 @@ import * as _ from 'lodash'; -export class IntervalUtils { - private mutex: {[intervalId: number]: boolean} = {}; - public setAsyncExcludingInterval(fn: () => Promise<void>, intervalMs: number) { +export const intervalUtils = { + setAsyncExcludingInterval(fn: () => Promise<void>, intervalMs: number) { + let locked = false; const intervalId = setInterval(async () => { - if (!_.isUndefined(this.mutex[intervalId])) { + if (locked) { return; } else { - this.mutex[intervalId] = true; + locked = true; await fn(); - delete this.mutex[intervalId]; + locked = false; } }); return intervalId; - } - public clearAsyncExcludingInterval(intervalId: number): void { + }, + clearAsyncExcludingInterval(intervalId: number): void { clearInterval(intervalId); - } -} + }, +}; |