node.js - 如何同时渲染页面执行函数调用
问题描述
使用带有把手的 NestJs,我有下面的代码
@Post('/foo')
@Render('foo')
async foobar(){
exemple();
return {x: x, y: y};
}
我的问题是:我需要打电话exemaple ()
而不是等待,继续return
我试图并行调用 async/await 函数,但await Promise.all([...])
作品只有函数调用,我需要调用exemple
和呈现页面(作为回报)
编辑——exemple()
函数是一个shell命令
var shell = require('shelljs')
shell.exec('some command here')
解决方案
根据文档,exec()
它不会异步执行,除非提供回调或async
选项设置为true
.
因此,要解决您的问题,请将其设置为异步:
shell.exec('some command here', {async: true})
推荐阅读
- react-native - 有什么办法可以在本机反应中实现双色调图像效果
- javascript - 快速路线范围
- python - 使用 txt 文件中的数据制作登录页面
- php - 单击提交按钮进行下一个sql查询时如何使用数据
- wordpress - woocommerce 使用 woo 过滤器插件和隐藏的缺货产品显示不正确的结果数量
- javascript - 将字符串的开头从 2 个空格转换为 4 个空格
- machine-learning - 用于非图像数据的 CNN
- c++ - 我的 STL 映射、列表、集合、向量、myCompareClass 的比较器类出错
- r - 如何将季度(chr)格式的日期转换为年月(日期)格式?
- python - 如果行与其上方的行相同,则向下填充/递增 1