Created
February 24, 2021 07:11
-
-
Save Bjorn-Eric-Abr/1c50f690c98a0b15cd509af050e075fe 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
| 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