ejecuta()
/**
* @param {string} res
* @param {number} timeout
*/
function prom(res, timeout) {
return new Promise(
(resolve, reject) =>
setTimeout(
() => {
if (res !== "") {
resolve(`Éxito[${res}]`)
} else {
reject(new Error(
`Falla[${res}]`))
}
},
timeout))
}
async function ejecuta() {
try {
const r1 = await Promise.all([
prom("a", 300),
prom("z", 2000),
prom("b", 5000)])
console.
log("Éxito 1:", r1.join())
} catch (e) {
console.
log("Falló 1:", e.message)
}
try {
const r2 = await Promise.all([
prom("a", 100),
prom("", 1000),
prom("b", 5000)])
console.log("Éxito 2:", r2)
} catch (e) {
console.
log("Falló 2:", e.message)
}
}