sindresorhus / p-map

Map over promises concurrently
MIT License
1.29k stars 58 forks source link

How can I add delay? #25

Closed dilipkumar2k6 closed 4 years ago

dilipkumar2k6 commented 4 years ago

Between two consecutive call, I would like to add delay, is it possible?

sindresorhus commented 4 years ago

The mapper waits for a promise/async-function, so you can use https://github.com/sindresorhus/delay in there.

(async () => {
    const mapper = async element => {
        // something here

        await delay(1000);

        // something here
    };

    const result = await pMap(array, mapper, {concurrency: 2});
})();