-
-
Save Xedii/9c6f6ea4171a171f42d910a85d936388 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mapLimit = async (arr, perChunk) => { | |
const promiseArr = arr.reduce((all,one,i) => { | |
const ch = Math.floor(i/perChunk); | |
all[ch] = [].concat((all[ch]||[]),one); | |
return all | |
}, []) | |
for (const promise of promiseArr) { | |
await Promise.all(promise.map(func => func())) | |
console.log('done!'); | |
} | |
return 'Success!!' | |
} | |
const promiseArr = [request, request, request, request, request, request, request, request, request, request, request, request] | |
(async () => { | |
try { | |
const limit = 3; | |
await mapLimit(promiseArr, limit); | |
} catch (err) { | |
console.log(err) | |
} | |
})(); | |
// or … | |
// ;(() => { | |
// mapLimit(datadad, 3).then(console.log).catch(console.error) | |
// })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment