Promise test
by Alexander Shutov
JavaScript
function read(msg, isError) {
return new Promise((resolve, reject) => {
if (isError) {
reject('error' + msg);
} else {
resolve(msg);
}
});
}
//console.error('wtf')
Promise.all([
read('a', false)
.then(res => res)
.catch(err => read('A'))
.then(res => alert(res)),
read('b', true)
.then(res => res)
.catch(err => read('B'))
.then(res => alert(res)),
read('c', false)
.then(res => {
throw 'err-c';
})
.catch(err => read('C'))
.then(res => alert(res)),
read('d', true)
.then(res => res)
.catch(err => read('D'))
.then(res => {
throw 'err-d';
})
])
.then(() => alert('done'))
.catch((err) => alert(err));