Files
30-seconds-of-code/snippets/sleep.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

548 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Delay async function execution function,promise sleepy-cat 2017-12-13T22:40:56+02:00 2020-10-22T20:24:30+03:00

Delays the execution of an asynchronous function.

  • Delay executing part of an async function, by putting it to sleep, returning a Promise.
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
async function sleepyWork() {
  console.log("I'm going to sleep for 1 second.");
  await sleep(1000);
  console.log('I woke up after 1 second.');
}