JavaScript sleep function
11 March 2022 (Updated 11 March 2022)
Here’s a handy little function that you can use to simulate a delay:
export async function sleep(milliseconds) {
return new Promise((resolve) => setTimeout(resolve, milliseconds))
}
You can use it like so:
class AuthController {
async register() {
await sleep(3000)
// do something
}
}
Tagged:
JavaScript
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment