Created
February 27, 2017 04:11
-
-
Save be9/50783338a2e47d6ed8881a0c2e57e1c0 to your computer and use it in GitHub Desktop.
An illustration of how ES6 promises work
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 zero(): Promise<number> { | |
console.log('zero'); | |
return 0; | |
} | |
async function add(origP: Promise<number>, inc: number): Promise<number> { | |
return inc + await origP; | |
} | |
(async () => { | |
const zP = zero(); | |
const one = await add(zP, 1); | |
const two = await add(zP, 2); | |
console.log(await zP, one, two); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment