title: How to nested promise.all
body: <p>I'm using es6 and have the following promises. What i want is the next Promise.all to wait for previous Promise.all to be completed before execute the next one. I have tried with the below codes but it's not working, only Promise 1 is resolved. </p>
  
  <pre><code>var deletePromises = [];
  arr.menuItems.forEach((item, idx) =&gt; {
    if (item.replace) {
       deletePromises.push(deleteFromFirebase(user.uid, item));
    }
  });
  
  // Promise 1
  Promise.all(deletePromises).then(res1 =&gt; {
    var uploadPromises = [],  updateRecordPromises = [];
  
    arr.menuItems.forEach((item, idx) =&gt; {
      uploadPromises.push(uploadToFirebase(user.uid, item));
    });
  
    // Promise 2
    Promise.all(uploadPromises).then(res2 =&gt; {
      arr.menuItems.forEach((item, idx) =&gt; {
        item.replace = false;
        updateRecordPromises.push(updateRecord(user.uid, item));
      });
  
      // Promise 3
      Promise.all(updateRecordPromises).then(res3 =&gt; { 
          console.log('All promise execute with successfully');
      });
   });
  });
  </code></pre>
  
  <p><strong>MarkM Answer</strong></p>
  
  <p>Try to use chaining as Mark suggest but the problem still there. I had found where the problem was, it is uploadPromises that never get resolved and then is never get called.</p>
  
  <p><strong>uploadToFirebase function</strong></p>
  
  <p>Stuck here, but the file is successfully  uploaded. I can see all the files.</p>
  
  <pre><code>const uploadToFirebase = (userid, item) =&gt; {
   return new Promise((resolve, reject) =&gt; {
      const uploadUri = Platform.OS === "ios"
        ? RNFetchBlob.wrap(item.pic_url.replace("file://", ""))
       : RNFetchBlob.wrap(item.pic_url);
  
      Blob.build(uploadUri, {
        type: "image/png;"
      }).then(blob =&gt; {
       // upload image using Firebase SDK
      firebase
      .storage()
      .ref("menu_items")
      .child(userid)
      .child(item.new_filename)
      .put(blob, { contentType: "image/png" })
      .then(snapshot =&gt; {
        console.log("Promise resolve: ", snapshot);
        resolve(snapshot);
        blob.close();
      })
      .catch(error =&gt; {
        reject(error.message);
      });
    });
   });
  };
  </code></pre>
  
  <p><strong>Updated code</strong></p>
  
  <p>console.log('Print res2') is not printed</p>
  
  <pre><code>var deletePromises = [],
  uploadPromises = [],
  updateRecordPromises = [];
  
  arr.menuItems.forEach((item, idx) =&gt; {
    if (item.replace) {
      deletePromises.push(deleteFromFirebase(user.uid, item));
    }
  });
  
  Promise.all(deletePromises)
  .then(res1 =&gt; {
    console.log("Print res1:", res1);
    arr.menuItems.forEach((item, idx) =&gt; {
      uploadPromises.push(uploadToFirebase(user.uid, item));
    });
  
    return Promise.all(uploadPromises);
  })
  .then(res2 =&gt; {
    console.log("Print res2:", res2);
    dispatch({ type: MENU_UPDATE_SUCCESS, payload: arr });
    dispatch(reset("menuItem"));
  })
  .catch(error =&gt; {
    console.log("Print error:", error);
  });
  </code></pre>