hd-utils
Version:
A handy utils for modern JS developers
12 lines (11 loc) • 378 B
JavaScript
/**
* @description Delays a function for the given number of milliseconds, and then calls it with the arguments supplied.
* @example delay(()=>{console.log(1)} , 1000) // will be called after 1s.
*/
export default function delay(cb, time = 200, ...args) {
return new Promise(res => {
setTimeout(() => {
res(cb?.(...args));
}, time);
});
}