Skip to content

Instantly share code, notes, and snippets.

@Bjorn-Eric-Abr
Created February 24, 2021 07:11
Show Gist options
  • Select an option

  • Save Bjorn-Eric-Abr/1c50f690c98a0b15cd509af050e075fe to your computer and use it in GitHub Desktop.

Select an option

Save Bjorn-Eric-Abr/1c50f690c98a0b15cd509af050e075fe to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch')
const pThrottle = require('p-throttle')
const throttle = pThrottle({
limit: 5,
interval: 2000
})
const throttled = throttle(step => {
return fetch(`https://jsonplaceholder.typicode.com/posts/${step}`)
})
for (let step = 0; step < 15; step++) {
throttled(step)
.then(data => data.json())
.then(console.log)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment