aboutsummaryrefslogblamecommitdiffstats
path: root/src/utils/interval_utils.ts
blob: 1656318e6da925c323d347ab3627d8ed1d4a475c (plain) (tree)
1
2
3
4
5
6
7
8
9

                            


                                                                            
                                                    
                         

                       
                              
                           
                               


                          

                                                           
                                  

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