Я упростил ваш пример, чтобы вы, надеюсь, поняли, что происходит:)
Вам нужно вернуть массив обещаний из массива, чтобы иметь возможность разрешить их с помощью Promise.all
нет смысла использовать await Promise.all().then
использовать await
или then
массив никогда не возвращал обещание запроса, поэтому, когда его ожидали, он был бы решен немедленно
сон, я не верю, что это также функция в узле.
любые вопросы, дайте мне знать, рады помочь.
const axios = {
get: async(task) => {
return task.res;
},
post: async(task) => {
return task;
}
}
const tasks = [{url: 'getting', res: {got: 'got the thing', post: 'thing to post'}}, {url: 'getting 2', res: {got: 'got the thing 2', post: 'thing to post 2'}}]
const getRequest = async(url = '') => {
const res = await axios.get(url)
console.log(res.got)
return postRequest(res.post)
}
const postRequest = async (url = '') => {
const res = await axios.post(url)
console.log(res)
return res;
}
const array = async() => {
const createRequests = async task => {
return getRequest(task)
}
return tasks.map(createRequests).filter(Boolean);
};
const promises = async() => {
console.log('waiting')
const res = await array()
const all = await Promise.all(res)
console.log('awaited')
console.log('can call your reset')
};
promises();