add sleep function - making delays in async functions

This commit is contained in:
iamsoorena
2017-12-14 00:10:56 +03:30
parent 280cefb801
commit 4a661d70f2

12
snippets/sleep.md Normal file
View File

@ -0,0 +1,12 @@
### Sleep
If you have an async function and you want to delay executing part of it. you can put your async function to sleep(in miliseconds).
```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.');
// }
```