promise未决议的情形
async function main() {
var ret = await step1();
}
function step1() {
return new Promise(function (resolve, reject) { console.log(1)/*resolve() */ })
}
main()
.then(function resolved() { console.log('成功啦')/*resolved状态的回调函数*/ },
function rejected() { console.log('失败啦') /*rejected状态的回调函数*/ })
当resolve(1)时
async function main() {
var ret = await step1();
}
function step1() {
return new Promise(function (resolve, reject) { resolve(1)/*resolve() */ })
}
main()
.then(function resolved(value) {
console.log('成功啦'); console.log(value)/*resolved状态的回调函数*/
},
function rejected(error) {
console.log('失败啦'); console.log(error) /*rejected状态的回调函数*/
})
//成功啦
//undefined
当reject(1)时
async function main() {
var ret = await step1();
}
function step1() {
return new Promise(func