Answer the question
In order to leave comments, you need to log in
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
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
await Promise.all(doc.map(item => (async(item) { /* ... */ })(item)))
doc.map(item => ...)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question