Debounce promise-returning & async functions
$ npm install p-debounce
const pDebounce = require('p-debounce');
const expensiveCall = async input => input;
const debouncedFn = pDebounce(expensiveCall, 200);
for (const i of [1, 2, 3]) {
debouncedFn(i).then(console.log);
}
//=> 3
//=> 3
//=> 3
Returns a function that delays calling fn
until after wait
milliseconds have elapsed since the last time it was called.
Type: Function
Promise-returning/async function to debounce.
Type: number
Milliseconds to wait before calling fn
.
Type: Object
Type: boolean
Default: false
Call the fn
on the leading edge of the timeout. Meaning immediately, instead of waiting for wait
milliseconds.
- p-throttle - Throttle promise-returning & async functions
- p-limit - Run multiple promise-returning & async functions with limited concurrency
- p-memoize - Memoize promise-returning & async functions
- debounce-fn - Debounce a function
- More…
MIT © Sindre Sorhus