Implement a mapLimit
function that behaves like Array.map
, but for asynchronous iteratees with a concurrency limit.
inputs
.limit
iteratees run concurrently.mapLimit([1, 2, 3, 4, 5], 3, (n, cb) => {
setTimeout(() => {
cb(null, n * 2);
}, 2000);
})
.then(res => console.log(res)) // [2, 4, 6, 8, 10]
.catch(console.error);