我每次打印都是Null,怎么样才能让res拿到了数据库返回的值才打印?
const userData = async () => {
function selectData(table) {
return new Promise((resolve, reject) => {
setTimeout((err, res) => {
const result = "hello";
if (result) {
resolve(result);
}
}, 2000);
});
}
const result = await selectData("hhh");
console.log(result);
};
userData();
https://www.jianshu.com/p/b16e7c9e1f9f promise async await