Last active
December 7, 2016 13:25
-
-
Save aherve/870a6469e232c1d1e4363ee46effef46 to your computer and use it in GitHub Desktop.
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
| // ----- Without async ----- // | |
| function regularPlusOne (i: number): Promise<number> { | |
| return new Promise(resolve => { | |
| resolve(i + 1) | |
| }) | |
| } | |
| // ----- With async ----- // | |
| async function plusOne (i: number): Promise<number> { | |
| return i + 1 | |
| } | |
| // Both functions can be used as | |
| plusOne(1) | |
| .then(plusOne) | |
| .then(plusOne) | |
| .then(console.log) // outputs 4 | |
| .catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment