1.async 修饰的函数返回结果是一个promise实例对象
//1.无返回值(返回一个状态成功值为undefined的promsie实例对象)
async function fn1() {}
let result1 = fn1()
console.log(result1); // Promise {<fulfilled>: undefined}
//2.1 返回非promise值(返回一个状态成功值为返回值的promsie实例对象)
async function fn2() {
return 'hello'
}
let result2 = fn2()
console.log(result2); // Promise {<fulfilled>: "hello"}
//2.2.1 返回成功的promise(返回一个状态成功、值为返回的promsie的成功值的promsie实例对象)
async function fn3() {
return Promise.resolve('success')
}
let result3 = fn3()
console.log(result3); // Promise {<fulfilled>: "success"}
//2.2.2 返回失败的promise(返回一个状态失败、值为返回的promsie的失败值的promsie实例对象)
async function fn4() {
return Promise.reject('failed')
}
let result4 = fn4()
console.log(result4); // Promise {<rejected>: "failed"}
//3.抛出异常(返回一个状态失败、值为异常值的promsie实例对象)
async function fn5() {
// throw new Error('error')
throw 'error'
}
let result5 = fn5()
console.log(result5); // Promise {<rejected>: "error"}