promise queue javascript

Solutions on MaxInterview for promise queue javascript by the best coders in the world

showing results for - "promise queue javascript"
Camilla
08 Feb 2019
1// promise queue
2const Queue = require('promise-queue');
3var maxConcurrent = 1;
4var maxQueue = Infinity;
5var queue = new Queue(maxConcurrent, maxQueue);
6
7(async () => {
8    const promises = [];
9    // logic here
10    function getDownloader() {
11        return async () => {
12            await new Promise((res, rej) => {
13                setTimeout(() => {
14                    console.log("hello data");
15                    res();
16                }, 3000);
17            })
18        };
19    }
20
21    for (let i = 0; i < 4; i++) {
22        promises.push(queue.add(getDownloader()))
23    }
24
25    const start = Date.now()
26    await Promise.all(promises)
27    console.log(Date.now() - start)
28
29})()
30