delay()
delay<
Args>(func,wait, ...args):Timeout
Invokes func after wait milliseconds.
DEPRECATED
Use setTimeout(fn, wait) directly instead.
Type Parametersβ
Args: Args extends unknown[]β
Parametersβ
func: (...args) => voidβ
The function to delay.
wait: numberβ
The number of milliseconds to delay invocation.
args: ...Argsβ
The arguments to invoke the function with.
Returns: Timeoutβ
The timer id.
See Alsoβ
Sinceβ
1.0.0
Also known asβ
delay (Lodash, es-toolkit) Β· β (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)
Exampleβ
// β Deprecated approach
delay(console.log, 1000, 'later');
// β
Recommended approach
setTimeout(() => console.log('later'), 1000);
How it works?β
Invokes func after wait milliseconds.
Deprecated: Use setTimeout() directly.
Native Equivalentβ
// β delay(fn, 1000, arg1)
// β
setTimeout(() => fn(arg1), 1000)
Use Casesβ
Delay execution πβ
Execute function after specified time.
setTimeout(() => {
showNotification();
}, 2000);
Debounce manuallyβ
Simple debounce pattern.
let timer;
const delayed = () => {
clearTimeout(timer);
timer = setTimeout(action, 300);
};
Sequence operationsβ
Chain timed operations.
await new Promise(r => setTimeout(r, 1000));
nextStep();