Created
November 21, 2019 11:39
-
-
Save ekibun/1ac57254a020803c94431b046fb31e09 to your computer and use it in GitHub Desktop.
async pool
This file contains hidden or 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
/* | |
* @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