one-function-at-time

1.0.2 • Public • Published

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

Package Sidebar

Install

npm i one-function-at-time

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

5.63 kB

Total Files

6

Last publish

Collaborators

  • mavlutovr