fn
<Function>
Function that will be rate-limitedoptions
<Object>
Configurable optionsmax
<number>
Maximum number of active instances. Default:10
delay
<number>
Minimum delay between calls in milliseconds. Default:10
- Returns:
<Function>
with the same signature asfn
import { rateLimit } from './rateLimit.js'
const ratedFetch = rateLimit(fetch)
// use .allSettled so that errors don't stop everything
Promise.allSettled([/* URLs to fetch */].map((url) => ratedFetch(url).then((r) => {
// process response as usual (e.g. `r.json()`)
})).then((results) => console.log('done', results))