function doubleAfter2seconds(num) {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(2 * num)
reject('我就是想要错')
}, 2000);
} )
}
async function timeout() {
await doubleAfter2seconds(45).catch(err=>{
console.log(err)
});
console.log('hello world')
return 'hello world'
}
timeout();
console.log('虽然在后面,但是我先执行');
仅为个人学习记录