Skip to content

Instantly share code, notes, and snippets.

@ecowden
Created January 18, 2016 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecowden/88da993e95f246401f1a to your computer and use it in GitHub Desktop.
Save ecowden/88da993e95f246401f1a to your computer and use it in GitHub Desktop.
Simple ES2016 async / await demo
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