one-function-at-time
v1.0.2
Published
Run functions in turn to prevent functions from running at the same time.
Downloads
3
Maintainers
Readme
one-function-at-time
Run functions in turn to prevent functions from running at the same time.
Demo
https://webdeveloper.pro/demo/one-function-at-time/demo/demo.html
Install
npm install one-function-at-time --save
Setup
const { OneFunctionAtTime } = require('one-function-at-time');
Usage
const queue = new OneFunctionAtTime();
// First function will run immediately
queue.add(next => {
console.log('start 1');
setTimeout(() => {
console.log('end 1');
next();
});
});
// Second function will run after first function finish
queue.add(next => {
console.log('start 2');
setTimeout(() => {
console.log('end 2');
next();
});
});
// start 1
// end 1
// start 2
// end 2
// Events
queue.on('start', () => {
console.log('Start functions');
});
queue.on('finish', () => {
console.log('All functions are finished');
});
License
MIT