1.0.2 • Published 3 years ago

one-function-at-time v1.0.2

Weekly downloads
7
License
MIT
Repository
github
Last release
3 years ago

one-function-at-time

Run functions in turn to prevent functions from running at the same time.

npm.io

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

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago