// promise
let promise = new Prommise((resolve, reject) => {
setTimeout(() => {
if (true) {
resolve({ name: "狗" });
} else {
reject("失败了");
}
});
}, 2000);
//promise.then(onCompleted, onRejected);
//onCompleted必需。承诺成功完成时要运行的履行处理程序函数。
//onRejected可选。承诺被拒绝时要运行的错误处理程序函数
promise.then(result => console.log(result));
// The role of catch is to catch the error of the previous function
promise.catch(error => console.log(error));
promise.then(result => console.log(result)) //{ name: "狗" }
.catch(error => console.log(error)) //失败了
// async returns a promise object
const fn = async() =>{}
async function fn(){}
//("Util").promisify (the wrapper method becomes a promise object)