justforuse / promise-limit-all

Promise all, but with max limit

Home Page:https://codesandbox.io/s/promise-limit-all-demo-v80u1

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Promise Limit All

npm npm

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

Codesandbox

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

About

Promise all, but with max limit

https://codesandbox.io/s/promise-limit-all-demo-v80u1


Languages

Language:JavaScript 100.0%