Thank you a lot, I will give it a try.
In the meantime, I managed to create a task and reuse it as class variable. I use the constructor to instantiate it, and not the suggested
# the childProcess inside myTask has always the same pid, so
# it's always the same process
if @myTask is null
@myTask = new Task(taskPath)
@myTask.on 'custom-event', (status) ->
# do something with the response
@myTask.start input, (response) ->
# callback to call after the task is done
The task is implemented as follows:
myDep = require 'dependency'
module.exports = (input) ->
return if input is null
callback = @async()
emit 'custom-event', 'started'
# work with my stuff here, eventually will call the callback
response = myDep.doSomething input
It seems to work ok, but I’m experiencing several
Unexpected end of input errors during the implementation, when I add apparently harmless lines of code. I’m getting through though. Moreover, one event does not seem to fire the callback properly.