Created
May 7, 2018 17:52
-
-
Save rubycut/e1a4c875d38f3d734a8b53513cf262f6 to your computer and use it in GitHub Desktop.
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
import pLimit from "p-limit" | |
import PromiseBar from "promise.bar" | |
PromiseBar.enable() | |
// set concurrency | |
const limit = pLimit(5) | |
// create array which we will use to throttle requests | |
const requests = [] | |
cities.map(async (city) => { | |
try { | |
city.streets.map((street) => { | |
// push all aync action to array as functions | |
requests.push(limit(() => street.postHttp())) | |
}) | |
} catch (error) { | |
log.error(error) | |
} | |
}) | |
// run the array with limit | |
await PromiseBar.all(requests) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment