delay
Using
Creates a delay for a specified number of milliseconds and returns a resolved promise after the delay.
Arguments
Argument | Type | Description | Example |
---|---|---|---|
ms | number | The input milliseconds | 0 1000 |
Returns
Promise
— Promise void
Examples
delay(2000).then(() => {
console.log('2 seconds have passed');
});
// Wait for 2 seconds
delay().then(() => {
console.log('No delay');
});
// Default delay (0 milliseconds)
(async () => {
await delay(1000);
console.log('1 second has passed');
})();
// Wait for 1 second using async/await