Skip to main content

sleep

TS JS Deno

Delays the execution of an asynchronous function.

Delay executing part of an async function, by putting it to sleep, returning a Promise.

typescript
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
typescript
async function sleepyWork() {
console.log("I'm going to sleep for 1 second.");
await sleep(1000);
console.log("I woke up after 1 second.");
}