好文章参考
异步神器Async-await介绍与填坑
阮一峰 async 函数
深入理解await与async
function asyncFn1() {
return new Promise(function (resolve, reject) {
setTimeout(function () {
if (true) {
console.log('resolve console1')
resolve('resolve return1')
} else {
reject('reject return1')
}
}, 2000)
})
}
function asyncFn2() {
return new Promise(function (resolve, reject) {
setTimeout(function () {
if (true) {
console.log('resolve console2')
resolve('resolve return2')
} else {
reject('reject return2')
}
}, 2000)
})
}
var value1 = async () => {
res1 = await asyncFn1()
console.log(res1)
console.log(0)
}
var value2 = async () => {
value2 = await asyncFn2()
console.log(value2)
console.log(1)
}
value1();
value2();
console.log(2)