典型的Promise模拟应用
编辑时间:2023-09-19 作者:金满斗 浏览量:578 来源:原创

典型的Promise模拟应用

async function getxx() {
    return await new Promise((resolve, reject) => {
        // 异步操作
            setTimeout(() => {
				if (5==6) {
					resolve('Promise 延迟 2 秒后 resolve');
				} else {
					reject("失败");
				}
                
            }, 2000);
    });
}

async function wo() {
    return await getxx(); // 这里的参数一般就是访问地址了
}

wo().then(value => {
    // 成功时的回调函数
    console.log(value);
}, error => {
    // 失败时的回调函数
    console.log(error);
});


来说两句吧