Hello Stackers, Throttles arbitrary code to execute a maximum number of times per interval. Best for making throttled API requests.
For example, making network calls to popular APIs such as Twitter is subject to rate limits. By wrapping all of your API calls in a throttle, it will automatically adjust your requests to be within the acceptable rate limits.
Unlike the throttle
functions of popular libraries like lodash and underscore, throttled-queue
will not prevent any executions. Instead, every execution is placed into a queue, which will be drained at the desired rate limit.
QuickStart
const throttledQueue = require('throttled-queue');
const throttle = throttledQueue(1, 1000); // at most make 1 request every second.
for (let x = 0; x < 100; x++) {
throttle(() => {
// make a network request.
return fetch('https://api.github.com/search/users?q=shaunpersad');
});
}
For the full docs please refer on here. cyaaa..