2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[JavaScript] Promise.all() の使いかた

Posted at

Promise.all()はPromiseオブジェクトを要素に持つ配列を引数にとり、すべてのPromiseオブエジェクトが解決するまで処理を待つ。

Promise.all([promise1, promise2, promise3]).then((value)=> {
  // すべてのpromiseが解決した後に行う処理
  // value = [promise1の結果, promise2の結果, promise3の結果]
});

map()メソッドやpush()メソッドと組み合わせて使う例

// Promiseを要素に持つ配列を作る
const promises = array.map((a) => {
  // Promiseオブジェクトをreturnする
});

// 配列にPromiseを追加する
promises.push(/*他のPromiseオブジェクト*/)

Promise.all(promise).then((value)=> {
  // すべてのPromiseが解決した後に行う処理
});
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?