aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/interval_utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/interval_utils.ts')
-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);
+ }
+}