如何在执行函数调用的同时呈现页面
How to render a page in same time execute a function call
使用带车把的 NestJs,我有下面的代码
@Post('/foo')
@Render('foo')
async foobar(){
exemple();
return {x: x, y: y};
}
我的问题是:我需要调用 exemaple ()
而不是等待它,继续 return
我尝试 但 await Promise.all([...])
只能调用函数,我需要调用 exemple
并呈现页面(在 return 中)
编辑--
exemple()
函数是一个 shell 命令
var shell = require('shelljs')
shell.exec('some command here')
根据 documentation of exec()
它不会异步执行,除非提供回调或 async
选项设置为 true
。
所以要解决您的问题,请将其设置为异步:
shell.exec('some command here', {async: true})
使用带车把的 NestJs,我有下面的代码
@Post('/foo')
@Render('foo')
async foobar(){
exemple();
return {x: x, y: y};
}
我的问题是:我需要调用 exemaple ()
而不是等待它,继续 return
我尝试 await Promise.all([...])
只能调用函数,我需要调用 exemple
并呈现页面(在 return 中)
编辑--
exemple()
函数是一个 shell 命令
var shell = require('shelljs')
shell.exec('some command here')
根据 documentation of exec()
它不会异步执行,除非提供回调或 async
选项设置为 true
。
所以要解决您的问题,请将其设置为异步:
shell.exec('some command here', {async: true})