1.0.2 • Published 5 years ago
@26brains/throttled-queue-decorator v1.0.2
Throttled Queue Decorator
Install
npm i @26brains/throttled-queue-decorator
Usage
const { createThrottle } = require('throttled-queue-decorator');
const throttle = createThrottle(2, 1000); // 2 requests per 1000 milliseconds
const func = (id) => axios.get(`http://example.com/record/${id}`);
const throttledFunc = throttle(func);
const main = async () => {
return await Promise.all([
throttledFunc(1),
throttledFunc(2),
throttledFunc(3),
])
}
//third request will be delayed by 1 second
main();
Tests
npm test
Example
node example/example.js
Credits
Use of single setTimeout()
event copied from https://github.com/shaunpersad/throttled-queue.