Skip to content

Instantly share code, notes, and snippets.

@kgsi
Created April 13, 2020 00:09
Show Gist options
  • Save kgsi/6e3fa9e8905b5403961e7229babcbee5 to your computer and use it in GitHub Desktop.
Save kgsi/6e3fa9e8905b5403961e7229babcbee5 to your computer and use it in GitHub Desktop.

非同期処理を同時に並列実行させる

await Promise.all(
   res.data.hoge.map((id, index) =>
      dispatch('hogeAction', { hogeId, id, params: config[index].params })
   )
)

非同期処理を順番に実行する

forEachだとawaitしても引数として渡すcallback内でしかawaitされないため、for文を使う

for (const [index, id] of res.data.hoge) {
  await dispatch('hogeAction', { hogeId, id, params: config[index].params })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment