Answer the question
In order to leave comments, you need to log in
How to abort Promise.all?
Hello. Tell me how you can interrupt promise.all, I will give an example below
let promisess = this.distribution.files.map(async(res) => {
// код......
})
Promise.all(promisess).then(() => {
// все отлично, без ошибок
}).catch(err => {
// Есть ошибка, останавливаем обработку promisess
})
Answer the question
In order to leave comments, you need to log in
Something like this:
function makeRejectable(...promisess) {
let reject;
const rejector = new Promise((_, r) => reject = r);
const promise = Promise.race([
Promise.all(promisess),
rejector
]);
return [promise, reject]
}
const [promise, reject] = makeRejectable(...promisess);
promise.then(console.log, console.error);
reject('reject');
Here _
let promisess = this.distribution.files.map(async(res) => {
return new Promise((resolve, reject) => {
// код
// если код выполнился с ошибкой - reject(), без ошибок - resolve()
});
});
Promise.all(promisess).then(() => {
// все отлично, без ошибок
}).catch(err => {
// Есть ошибка, останавливаем обработку promisess
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question