Skip to content

Instantly share code, notes, and snippets.

@kdnk
Created November 12, 2016 08:52
Show Gist options
  • Save kdnk/9c0a26397913cf8fe6ee995a9f6693a9 to your computer and use it in GitHub Desktop.
Save kdnk/9c0a26397913cf8fe6ee995a9f6693a9 to your computer and use it in GitHub Desktop.
async/await
async function main () {
const user = await getUser('kodai', 'nakamura')
const email = await getEmail(user)
return email
}
main()
.then(email => {
console.log(email)
})
function getUser (first, last) {
return new Promise((resolve, reject) => {
resolve(`${first}_${last}`)
})
}
function getEmail (user) {
return new Promise((resolve, reject) => {
resolve(`${user}@sample.com`)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment