1.0.0 • Published 5 years ago

requestcq v1.0.0

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

requestcq

Asynchronous queue to handle request concurrency

Installation

npm install requestcq

Usage

import Queue from 'requestcq'

// test function
function async(data) {
    return new Promise(function(resolve, reject){
        setTimeout(function(){
            console.log("resolving", data);
            resolve(data);
        }, Math.random() * 5000);
    });
}

var queue = new Queue(async);

Promise.all(
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50].map(queue.push.bind(queue))
).then((result) => {
    console.log(result); 
});

Test

npm test

Exmpale

git clone https://github.com/geekfarmeropensource/requestcq

npm install

node -r esm ./exmpale/index.js