Created
November 14, 2017 04:43
-
-
Save cyan33/deec87cc06c3a54476d317b9a9f77ed4 to your computer and use it in GitHub Desktop.
Basic example about how to use async and await in 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
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