Exponential Rate Limit
A small library which handles decaying exponential backoff. This is useful if you want to start throttling something whilst it is going wrong, but recover once things start working again.
Demo
The demo source is in "demo.ts".
To run the demo locally run npm run start
.
It is also hosted here (thanks to Netify).
Usage
; ;
Example
The following example implements throttledFetch
, which will start delaying future executions exponentially (up to the default 5 seconds) every time a request fails or does not respond with status 200.
Every time there is a 200 response, the delays will also start getting shorter again. As time passes without any jobs being executed, the delay the next job would incur also decreases.
; ; // default options
Browser
This can also be used in the browser thanks to jsDelivr: