0.1.0 • Published 3 years ago

promise-limit-all v0.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Promise Limit All

npm npm

This package let you control the number of async function at the same time

Demo

const promiseLimitAll = require('promise-limit-all');

const promiseFactory = (res, timeout) => {
    return () =>
        new Promise((resolve) => {
            setTimeout(() => {
                resolve(res);
            }, timeout);
        });
};

promiseLimitAll(
    [
        promiseFactory(1, 1000),
        promiseFactory(2, 2000),
        promiseFactory(3, 2000),
        promiseFactory(4, 1000),
        promiseFactory(5, 1000),
        promiseFactory(6, 500),
        promiseFactory(7, 500)
    ],
    3
).then((res) => {
    const str = res.join(",");
    console.log(str);
});

Output:

1,2,3,4,5,6,7