Last active
December 3, 2022 11:52
-
-
Save tohagan/d8e0adaf88fa2bc489f82c7cc9097a0f to your computer and use it in GitHub Desktop.
delay() using a Promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requires Node 16 or later | |
import { setTimeout } from 'timers/promises'; | |
const result = await setTimeout(2000, 'done'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function delay(msecs: number) { | |
return new Promise((resolve) => setTimeout(resolve, msecs)); | |
} | |
await delay(2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment