Skip to content

Instantly share code, notes, and snippets.

@be9
Created February 27, 2017 04:11
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 be9/50783338a2e47d6ed8881a0c2e57e1c0 to your computer and use it in GitHub Desktop.
Save be9/50783338a2e47d6ed8881a0c2e57e1c0 to your computer and use it in GitHub Desktop.
An illustration of how ES6 promises work
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