Last active
May 17, 2017 23:25
-
-
Save warrenca/9f11ceef456a3603d42d4c23b359e409 to your computer and use it in GitHub Desktop.
Async/Await ES7
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 process() { | |
let name="john"; | |
if (name==="john") { | |
return Promise.resolve("My name is john"); | |
} else { | |
return Promise.reject("I am not john"); | |
} | |
} | |
async function start() { | |
try { | |
let response = await process(); // waiting for the promise | |
console.log(response); // promise response | |
} catch (error) { // will go here if you're not john | |
console.error(error); | |
} | |
} | |
start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out the corresponding callback-hell example -
https://gist.github.com/warrenca/732f5dc4255e14978e5eabe30187616a or in babel