let runPromiss = (name, time, status) => {
return new Promise((resolve, reject) => {
if(status) {
console.log(`${name} 起跑了!`)
return setTimeout(() => {
console.log(`${name} 衝了 ${time / 1000}秒`)
},time);
} else {
reject(new Error(`${name} 出現錯誤`));
};
});
};
// 小明失敗,就回傳錯誤訊息
runPromiss('小明', 3000, true).then((res) => {
console.log(res);
return runPromiss('小王', 1000, true)
}).then((res) => {
console.log(res);
}).catch((error) => {
console.log(error);
})
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.