Debounce promise-returning & async functions
import pDebounce from 'p-debounce'; const expensiveCall = async input => input; const debouncedFunction = pDebounce(expensiveCall, 200); for (const number of [1, 2, 3]) { (async () => { console.log(await debouncedFunction(number)); })(); } //=> 3 //=> 3 //=> 3pDebounce(fn, wait, options?)
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.
Execute function_
unless a previous call is still pending, in which case, return the pending promise. Useful, for example, to avoid processing extra button clicks if the previous one is not complete.
Type: Function
Promise-returning/async function to debounce.
import {setTimeout as delay} from 'timers/promises'; import pDebounce from 'p-debounce'; const expensiveCall = async value => { await delay(200); return value; } const debouncedFunction = pDebounce.promise(expensiveCall); for (const number of [1, 2, 3]) { (async () => { console.log(await debouncedFunction(number)); })(); } //=> 1 //=> 1 //=> 1
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4