diff options
Diffstat (limited to 'src/utils/interval_utils.ts')
-rw-r--r-- | src/utils/interval_utils.ts | 20 |
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..1656318e6 --- /dev/null +++ b/src/utils/interval_utils.ts @@ -0,0 +1,20 @@ +import * as _ from 'lodash'; + +export const intervalUtils = { + setAsyncExcludingInterval(fn: () => Promise<void>, intervalMs: number) { + let locked = false; + const intervalId = setInterval(async () => { + if (locked) { + return; + } else { + locked = true; + await fn(); + locked = false; + } + }); + return intervalId; + }, + clearAsyncExcludingInterval(intervalId: number): void { + clearInterval(intervalId); + }, +}; |