首页 > 解决方案 > 如何将 async / await 与辅助函数一起使用?

问题描述

我很难理解异步/等待。如何让 test() 函数等待运行其余代码,直到 helper() 函数完成?

谢谢!

async function test() {
    await helper();
    console.log("world");
}

function helper() {
    setTimeout(() => {
        console.log("hello");
    }, 3000);
}

标签: javascriptasynchronousasync-await

解决方案


推荐阅读