Skip to content

Instantly share code, notes, and snippets.

@bojand
Created November 17, 2017 18:49
Show Gist options
  • Save bojand/ac7aa0c11a735551265d2180a61bb19c to your computer and use it in GitHub Desktop.
Save bojand/ac7aa0c11a735551265d2180a61bb19c to your computer and use it in GitHub Desktop.
async + await

asynctest.js

function foo() {
  return 'bar'
}

async function afoo() {
  return 'bar'
}

async function main() {
  console.log('foo()')
  console.log(foo())
  console.log('\r\n')
  console.log('await foo()')
  console.log(await foo())
  console.log('\r\n')
  console.log('afoo()')
  console.log(afoo())
  console.log('\r\n')
  console.log('await afoo()')
  console.log(await afoo())
}

main()

output:

$ node asynctest.js
foo()
bar


await foo()
bar


afoo()
Promise { 'bar' }


await afoo()
bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment