📜  在异步块内包装残骸请求 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:25.202000             🧑  作者: Mango

代码示例1
const asyncOperation = () => {
    return new Promise((resolve, reject) => {
        setTimeout(()=>{resolve("hi")}, 3000)
    })
}

const asyncFunction = async (callback) => {
    let res = await asyncOperation();
    callback(res);
}

const topDog = () => {
    let callback = (res) => {
        console.log(res);
    };

    (async () => {
        await asyncFunction(callback)
    })()
}