// 面试的示例一,必须三轮都通过才可以
(async function () {
try {
const res = await Promise.all([mianshi(1),mianshi(2),mianshi(3)])
console.log('smile' + res)
} catch (error) {
return console.log(error)
}
})()
function mianshi(round) {
return new Promise((resolve, reject) => {
const score = Math.random()
if (score > 0.5) {
setTimeout(() => {
resolve('通过,分数:' + score)
}, 500)
} else {
setTimeout(() => {
reject('失败:第' + round + "轮,分数:" + score)
}, 500)
}
})
}