Created
November 14, 2017 17:41
-
-
Save cyan33/1bc5c1431e7d15d5406aeb168a12c200 to your computer and use it in GitHub Desktop.
async / await are just the syntax sugar of generators
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 addTwoResult(a, b) { | |
var first = await resolveAfter2Seconds(a); | |
var second = await resolveAfter2Seconds(b); | |
return first + second; | |
} | |
// is equivalent to | |
function *addTwoResult(a, b) { | |
var first = yield resolveAfter2Seconds(a); | |
var second = yield resolveAfter2Seconds(b); | |
return first + second; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment