549 B
549 B
title, type, language, tags, cover, dateModified
| title | type | language | tags | cover | dateModified | ||
|---|---|---|---|---|---|---|---|
| Delay async function execution | snippet | javascript |
|
sleepy-cat | 2020-10-22T20:24:30+03:00 |
Delays the execution of an asynchronous function.
- Delay executing part of an
asyncfunction, by putting it to sleep, returning aPromise.
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.');
}