1
0

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 1 year has passed since last update.

Promiseのループ処理と終わってから何かする

Last updated at Posted at 2022-02-07

調べてみたらこういう書き方もあるようだ。

        const items = [1, 2, 3];
        const boxes = [1, 2, 3];

        var myPromise = Promise.resolve();
        for (const item_id of items) {
              myPromise = myPromise.then(update.bind(this, item_id));
        }
        for (const box_id of boxes) {
              myPromise = myPromise.then(edit.bind(this, box_id));
        }
        myPromise.then(function(){
            return new Promise(function (resolve, reject) {
                alert("end");
                resolve();
            });
        })


1
0
2

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?