aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-09-06 23:41:40 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-09-06 23:41:40 +0800
commita57b22a6bc20df951c70212943b018ba8039a914 (patch)
tree81a9f87d775b245fa165893227fd06cbe376f20d /src/utils
parent7c61b09dce6ea294013a4745895b58ad855817a0 (diff)
downloaddexon-0x-contracts-a57b22a6bc20df951c70212943b018ba8039a914.tar.gz
dexon-0x-contracts-a57b22a6bc20df951c70212943b018ba8039a914.tar.zst
dexon-0x-contracts-a57b22a6bc20df951c70212943b018ba8039a914.zip
Fix overlapping async intervals issue
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/interval_utils.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/utils/interval_utils.ts b/src/utils/interval_utils.ts
new file mode 100644
index 000000000..23e6acc5b
--- /dev/null
+++ b/src/utils/interval_utils.ts
@@ -0,0 +1,20 @@
+import * as _ from 'lodash';
+
+export class IntervalUtils {
+ private mutex: {[intervalId: number]: boolean} = {};
+ public setAsyncExcludingInterval(fn: () => Promise<void>, intervalMs: number) {
+ const intervalId = setInterval(async () => {
+ if (_.isUndefined(this.mutex[intervalId])) {
+ return;
+ } else {
+ this.mutex[intervalId] = true;
+ await fn();
+ delete this.mutex[intervalId];
+ }
+ });
+ return intervalId;
+ }
+ public clearAsyncExcludingInterval(intervalId: number): void {
+ clearInterval(intervalId);
+ }
+}