Skip to content

Instantly share code, notes, and snippets.

@rubycut
Created May 7, 2018 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubycut/e1a4c875d38f3d734a8b53513cf262f6 to your computer and use it in GitHub Desktop.
Save rubycut/e1a4c875d38f3d734a8b53513cf262f6 to your computer and use it in GitHub Desktop.
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