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, 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);
- }
-}
+ },
+};