Skip to content

Instantly share code, notes, and snippets.

@aherve
Last active December 8, 2016 02:21
Show Gist options
  • Select an option

  • Save aherve/7e628a6ec14ee5883af51a8b80bdb1d3 to your computer and use it in GitHub Desktop.

Select an option

Save aherve/7e628a6ec14ee5883af51a8b80bdb1d3 to your computer and use it in GitHub Desktop.
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