javascript - 如何将 async / await 与辅助函数一起使用?
问题描述
我很难理解异步/等待。如何让 test() 函数等待运行其余代码,直到 helper() 函数完成?
谢谢!
async function test() {
await helper();
console.log("world");
}
function helper() {
setTimeout(() => {
console.log("hello");
}, 3000);
}
解决方案
推荐阅读
- c++ - 在 CMake 的头文件中包含外部头文件
- php - 在 Laravel Blade 中循环时限制 html 元素
- python - 我如何计算打印了多少次?
- powershell - 使用 PowerShell 从 TFS 工作项目(TASK/BUG)下载 SQL 脚本
- python - 如何使用APScheduler添加每天在固定时间开始并在固定时间完成的作业
- node.js - TypeError `[ERR_INVALID_CALLBACK]`:在 NodeJs 上
- apache-kafka - 在 burrow 配置的拒绝列表中添加控制台使用者的原因
- string - 字符串比较总是正确的
- ruby-on-rails - 使用 arel_predicates 和正则表达式编写带有 ransack 的自定义过滤器 (RoR 6)
- android - 如何在颤动的android中捕获音频输出(扬声器,耳机等),而不是输入(麦克风)?