A blazing slow library to deal with rate limited APIs
yarn add slowrate
npm i slowrate
You need to use an API that allows only a certain number of the request to be made in a given interval but don't want to bother implementing your rate limit solution.
slowrate
enables you to make requests without worrying about all the delay logic. Just submit your promise wrapper to a SlowRate instance and wait until the promise resolves.
import SlowRate from "slowrate"
const slowRate = new SlowRate({ interval: 500 })
const response = await slowRate.submit(() => fetchDataFromRateLimitedAPI())
Creates a new SlowRate
instance.
intervals
- Optional - Sets the interval between each request call in milliseconds. Defaults to500
A SlowRate
instance.
Submit a promise to the slowrate queue.
A function
that returns a Promise
. This is called by the slowrate instance to start the promise.
An optional number
that represents the priority of the request (request with higher priorities are resolved first). Defaults to 0
.
A Promise
that resolves to the result of the passed promise (or reject with the rejection error).
The number of promises enqueued in the slowrate instance.
A number
that represents the number of promises enqueued in the slowrate instance.
MIT