Skip to content

Instantly share code, notes, and snippets.

@warrenca
Last active May 17, 2017 23:25
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 warrenca/9f11ceef456a3603d42d4c23b359e409 to your computer and use it in GitHub Desktop.
Save warrenca/9f11ceef456a3603d42d4c23b359e409 to your computer and use it in GitHub Desktop.
Async/Await ES7
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();
@warrenca
Copy link
Author

warrenca commented Mar 3, 2017

Check out the corresponding callback-hell example -
https://gist.github.com/warrenca/732f5dc4255e14978e5eabe30187616a or in babel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment