Created
January 18, 2016 18:22
-
-
Save ecowden/88da993e95f246401f1a to your computer and use it in GitHub Desktop.
Simple ES2016 async / await demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function (t) { | |
// getDataAsync could be any function that returns a Promise | |
let aPromise = getDataAsync() | |
let a = await aPromise | |
// We usually don't assign the promise to a variable before we | |
// `await` it, so this process usually looks like, | |
let b = await getDataAsync() | |
// The values of `a` and `b` are available. The promises have | |
// been resolved for us by `await` so we don't need to call | |
// `.then(...)`. | |
doSomething(a, b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment