🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-fun-queue

a simple queue executing async functions linearly with pause/resume

1.0.1
latest
Version published
Weekly downloads
9
800%
Maintainers
1
Weekly downloads
 
Created

async-fun-queue

Build Status Images

A simple queue executing async functions linearly with pause/resume

Installation

npm install async-fun-queue

Example

The most common use case:

var queue = new AsyncQueue([1, 2, 3], function (job, done) {
    collection.push(job);
    // simulate async
    setTimeout(function () {
        done();
    }, 100);
});
queue.on('jobStart', function (job) {
    // job begin to run
});
queue.on('jobDone', function (job) {
    // job is done
});
queue.on('end', function () {
    // all jobs are done
});

queue.run();

A more complicated use case, with pause and resume method to controll the execution process:

var queue = new AsyncQueue([1, 2, 3], function (job, done) {
    setTimeout(function () {
        done();
        if (job === 2) {
            queue.pause();
            setTimeout(function () {
                queue.resume();
            }, 100);
        }
    }, 100);
});
queue.on('pause', function () {
    // queue is paused
});
queue.on('resume', function () {
    // queue is resumed
});

queue.run();

FAQs

Package last updated on 06 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts