由于一直记录在印象笔记里,好久好久没更新博客了。。。
async 函数的返回值是一个在 pending 状态的 Promise
var asyncReturn = async () => {
await promiseFn()
return 111
}
var c = asyncReturn()
console.log(c instanceof Promise) // true
async 如果被 await 住,他的返回值会被复制给变量,这种情况是不会要 catch 的
var promiseFn = () => new Promise((resolve, reject) => {
setTimeout(() => {resolve(111)}, 1000)
})
var asyncReturn = async () => {
await promiseFn()
return 111
}
var resultFn = async() => {
var getValue = await asyncReturn()
alert(getValue)
}
var c = asyncReturn()
console.log(c)
如果 Promise 执行失败,则不会继续执行,这个和 Promise 的行为一致