aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/interval_utils.ts
blob: 1656318e6da925c323d347ab3627d8ed1d4a475c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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);
    },
};