The number of milliseconds to delay
The function to execute after the delay
A promise that resolves after the action is executed
// Simple delay
await delayAction(1000, () => console.log("Delayed message"));
// With complex function
await delayAction(500, () => {
processData();
updateUI();
});
// In a sequence
await delayAction(100, step1);
await delayAction(200, step2);
export async function delayAction(ms: number, action: () => void) {
await sleep(ms);
action();
}
Delays the execution of an action by the specified number of milliseconds. Combines sleep() with a callback function for cleaner async code.