Skip to content

Instantly share code, notes, and snippets.

@tohagan
Last active December 3, 2022 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tohagan/d8e0adaf88fa2bc489f82c7cc9097a0f to your computer and use it in GitHub Desktop.
Save tohagan/d8e0adaf88fa2bc489f82c7cc9097a0f to your computer and use it in GitHub Desktop.
delay() using a Promise
// Requires Node 16 or later
import { setTimeout } from 'timers/promises';
const result = await setTimeout(2000, 'done');
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