Created
November 12, 2016 08:52
-
-
Save kdnk/9c0a26397913cf8fe6ee995a9f6693a9 to your computer and use it in GitHub Desktop.
async/await
This file contains 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 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