1.0.2 • Published 5 years ago

@26brains/throttled-queue-decorator v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

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.

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago