Merge pull request #84 from iamsoorena/master

add sleep function - making delays in async functions
This commit is contained in:
Angelos Chalaris
2017-12-14 10:34:47 +02:00
committed by GitHub

12
snippets/sleep.md Normal file
View File

@ -0,0 +1,12 @@
### Sleep
Delay executing part of an `async` function, by putting it to sleep, returning a `Promise`.
```js
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.');
// }
```