javascript - Node.js : 在后台运行函数
问题描述
我需要在后台运行该功能
function bk () {
console.log("Function Start");
var i;
for (i = 0; i < 10000000000; i++) {
y = 0
}
console.log("Function END");
}
console.log("MAIN START");
bk()
console.log("MAIN end");
目前的输出是:
MAIN START
Function Start
Function END
MAIN end
所需的输出是:
MAIN START
MAIN end
Function Start
Function END
或者
MAIN START
Function Start
MAIN end
Function END
想法是 JS 不应该等待函数结束打印“MAIN END”
解决方案
这应该这样做: -
console.log("MAIN START");
setTimeout(bk,0);
console.log("MAIN end");
推荐阅读
- android - 不要将对象添加到 recyclerview
- javascript - 如果用户有管理员,不要删除消息?
- mysql - 总结 MySQL 查询结果的问题
- go - 在 Go HTTP 处理程序中使用未导出的结构键获取上下文值时为 nil
- r - 如何根据ggplot2中的第二个变量更改具有相同形状的点子集的内部颜色(填充)?
- jdbc - CREATE USER 和 CREATE ROLE as PreparedStatement with ? 占位符
- firebase - 如何将下载网址保存为视频 ID 并将其上传到 Firebase?
- go - 如果所有字段都通过,Golang MySQL Scan 仅填充结果
- python - 如何遍历python中的嵌套列表?
- firebase - firebase 实时数据库整数数据类型有限制吗?大值集有时会自动舍入