Skip to content

Wrapper for setInterval function to prevent overlapping execution

License

Notifications You must be signed in to change notification settings

orlangure/set-interval-serial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

set-interval-serial

Wrapper for setInterval function to prevent overlapping execution

Extends setInterval and prevents the same function to start unless its previous execution is completed. Useful when running async tasks that can take time, but cannot run in parallel.

const setIntervalSerial = require('set-interval-serial');
const setTimeoutPromise = require('util').promisify(setTimeout);

const asyncFunction = async () => {
    await setTimeoutPromise(1000);
    console.log('Executing...');
};

// the output will appear every second, although the interval is set to 50ms
setIntervalSerial(asyncFunction, 50);

About

Wrapper for setInterval function to prevent overlapping execution

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages