Function: delay()
delay(
ms):Promise<void>
Wait for a time before resolving, without blocking the event loop (a promise of setTimeout). The wait cannot be cancelled.
Parameters
ms
number
The time to wait, in milliseconds. A negative or NaN value is taken as 0 (the next turn of the event loop); as for setTimeout, a value above 2147483647 waits 1 millisecond (Node.js prints a warning).
Returns
Promise<void>
A promise resolved with undefined once the time has passed; it never rejects.
Example
typescript
import {delay} from 'lakutata/utils'
const start: number = Date.now()
await delay(500)
console.log(Date.now() - start >= 500)
//true