S
S
sinevik2018-06-28 12:15:48
JavaScript
sinevik, 2018-06-28 12:15:48

How to correctly shove all my asynchronous Promise.all functions?

Tell me please. How to do it correctly so that until the block of code number 1 is executed, action number 2 is not performed
5b34a71e0813b898238471.png

export const getAllQues = (collection) => {
  return async (dispatch) => {
    const db = firebase.firestore();
    const settings = { timestampsInSnapshots: true };
    db.settings(settings);
    const allquestions = {};
    const docRef = db.collection(collection);
    try {
      const doc = await docRef.get();
      doc.forEach(async (item) => {
        const array = [];
        const ref = db.collection(collection).doc(item.id).collection('questions');
        const total = await ref.get();
        total.forEach(async (interval) => {
          array.push(interval.data());
        });
        allquestions[item.id] = array;
      });
    } catch (e) {
      throw e;
    }
    const result = allquestions;
    dispatch(allQues(result));
    return result;
  };
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-06-28
@Xuxicheta

await Promise.all(doc.map(item => (async(item) { /* ... */ })(item)))

doc.map(item => ...)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question