Skip to content

Instantly share code, notes, and snippets.

@cyan33
Created November 14, 2017 04:43
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 cyan33/deec87cc06c3a54476d317b9a9f77ed4 to your computer and use it in GitHub Desktop.
Save cyan33/deec87cc06c3a54476d317b9a9f77ed4 to your computer and use it in GitHub Desktop.
Basic example about how to use async and await in ES7
function resolveAfter2Seconds(x) {
return new Promise(resolve => {
setTimeout(() => {
resolve(x);
}, 2000);
});
}
async function addTwoResult(a, b) {
var first = await resolveAfter2Seconds(a);
var second = await resolveAfter2Seconds(b);
return first + second;
}
addTwoResult(3, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment