Skip to content

Instantly share code, notes, and snippets.

@taniarascia
Last active February 13, 2024 07:48
Show Gist options
  • Select an option

  • Save taniarascia/1aba40266c414814f06b0ec1c7597d87 to your computer and use it in GitHub Desktop.

Select an option

Save taniarascia/1aba40266c414814f06b0ec1c7597d87 to your computer and use it in GitHub Desktop.

Revisions

  1. taniarascia revised this gist Mar 20, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions async.js
    Original file line number Diff line number Diff line change
    @@ -2,16 +2,16 @@ method1 = async () => {
    const things = await getThings()

    for (let thing of things) {
    const stuff = getStuffFromThing(thing)
    const stuff = await getStuffFromThing(thing)
    console.log(stuff) // works
    }
    }

    method2 = async () => {
    const things = await getThings()

    await Promise.all(things.map(thing => {
    const stuff = getStuffFromThing(thing)
    await Promise.all(things.map(async thing => {
    const stuff = await getStuffFromThing(thing)
    console.log(stuff) // works
    }))
    }
  2. taniarascia created this gist Mar 20, 2019.
    17 changes: 17 additions & 0 deletions async.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    method1 = async () => {
    const things = await getThings()

    for (let thing of things) {
    const stuff = getStuffFromThing(thing)
    console.log(stuff) // works
    }
    }

    method2 = async () => {
    const things = await getThings()

    await Promise.all(things.map(thing => {
    const stuff = getStuffFromThing(thing)
    console.log(stuff) // works
    }))
    }