Last active
December 8, 2016 02:21
-
-
Save aherve/7e628a6ec14ee5883af51a8b80bdb1d3 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
| import {sleep} from 'previousExample' | |
| async function slowDouble (i): Promise<number> { | |
| await sleep(1000) // non-blocking | |
| return 2 * i | |
| } | |
| async function main () { | |
| // slowDouble is async, therefore it returns a promise | |
| const result = await Promise.all([1, 2, 3].map(slowDouble)) | |
| console.log(result) | |
| } | |
| main() // outputs [2, 4, 6] after 1000ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment