0

Using NestJs with handlebars, I have the code below

@Post('/foo')
@Render('foo')
async foobar(){
    exemple();
    return {x: x, y: y};
}

My problem is: I need to call exemaple () and not wait for it, proceed toreturn

I tried to Call async/await functions in parallel but the await Promise.all([...]) works only functions calls, i need to call exemple and render the page (in return)

EDIT-- The exemple() function is an shell command

var shell = require('shelljs')    
shell.exec('some command here')
Matheus
  • 301
  • 3
  • 16
  • So the return value of `example()` is not needed for the page rendering? It should just call the function an not care about its execution at all? Because if `example()` is asynchronous, that's exactly what your code is doing. – Kim Kern Aug 14 '19 at 14:36
  • I also thought it would have exactly this behavior, but the page only renders when the `exemple()` finishes executing .. which to me does not make much sense. – Matheus Aug 14 '19 at 20:26
  • What are you doing in `example()`? Is it really not a synchronous execution? – Kim Kern Aug 14 '19 at 20:38
  • Its an shell commando call, i added in EDIT – Matheus Aug 15 '19 at 20:59
  • Still having problems? :) – Kim Kern Aug 19 '19 at 14:18
  • 1
    I did not forget to test your solution, but I have not had time to test, because I needed to change OS and I am having problems with this change. But I looked at the link you left and it looks pretty promising – Matheus Aug 19 '19 at 16:40

1 Answers1

1

According to the documentation of exec() it is not executed asynchronously unless a callback is provided or the async option is set to true.

So to solve your problem set it to async:

shell.exec('some command here', {async: true})
Kim Kern
  • 54,283
  • 17
  • 197
  • 195