Skip to content

Instantly share code, notes, and snippets.

@akinjide

akinjide/async_await.js

Last active May 14, 2017
Embed
What would you like to do?
Understanding Async/Await
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
async function breathe(log) {
log('Breathe in @@@')
await delay(3000)
log('Breathe out')
await delay(1000)
log('3 @@@')
await delay(1000)
log('2 @@@')
await delay(1000)
log('1 @@@')
await delay(1000)
log('Breathe in @@@')
return 'Good job!'
}
breathe(console.log)
.then(console.log)
.catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.