Package Exports
- p-throttle
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (p-throttle) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
p-throttle 
Throttle promise-returning & async functions
It also works with normal functions.
Useful for rate limiting calls to an external API, for example.
Install
$ npm install --save p-throttleUsage
Here, the trottled function is only called twice a second:
const pThrottle = require('p-throttle');
const now = Date.now();
const throttled = pThrottle(i => {
const secDiff = ((Date.now() - now) / 1000).toFixed();
return Promise.resolve(`${i}: ${secDiff}s`);
}, 2, 1000);
for (let i = 1; i <= 6; i++) {
throttled(i).then(console.log);
}
//=> 1: 0s
//=> 2: 0s
//=> 3: 1s
//=> 4: 1s
//=> 5: 2s
//=> 6: 2sAPI
pThrottle(fn, limit, interval)
Returns a throttled version of fn.
fn
Type: Function
Promise-returning/async function or a normal function.
limit
Type: number
Maximum number of calls within an interval.
interval
Type: number
Timespan for limit.
Related
- p-debounce - Debounce promise-returning & async functions
- p-limit - Run multiple promise-returning & async functions with limited concurrency
- p-memoize - Memoize promise-returning & async functions
- More…
License
MIT © Sindre Sorhus