Skip to content

Instantly share code, notes, and snippets.

@ekibun
Created November 21, 2019 11:39
Show Gist options
  • Save ekibun/1ac57254a020803c94431b046fb31e09 to your computer and use it in GitHub Desktop.
Save ekibun/1ac57254a020803c94431b046fb31e09 to your computer and use it in GitHub Desktop.
async pool
/*
* @Description: async pool
* @Author: ekibun
* @Date: 2019-11-21 15:30:04
* @LastEditors: ekibun
* @LastEditTime: 2019-11-21 19:33:27
*/
async function queue(fetchs, run, num = 2) {
await Promise.all(new Array(num).fill(0).map(async () => {
while (fetchs.length) await run(fetchs.shift())
}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment