LoginSignup
4
2

More than 5 years have passed since last update.

map内の即時関数をawait処理したい。(自分メモ)

Last updated at Posted at 2018-10-03

map内の即時関数をawait処理したい。

map内は別のスコープになるので一つ外でasyncしてもawaitが掛からない。
Promise.allでawait


async() => {
  const data = [1,2,3,4]
  try {
    const result = await Promise.all( 
      data.map(async(key) => {
        return await await_function(key)
    })
  } catch(e){
    //error
  }

ポイントは await Promise.all()

おまけ
Promise.all がオブジェクトを返す。

const result = await Promise.all(data.map(...))

以下で変わっているわけでない。

Promise.all(result)
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2