Closed devonoel closed 9 years ago
This is solved in branch async-exec, though the branch is still in development, and brings up another issue: how to actually handle the completion of a task execution (and for that matter, how to capture and communicate stdout
from the task executing).
EventEmitter
is my first instinct, though it'll require an expansion of the API and increase complexity on the client sideexec
a callback, but this will (as far as I can conceive) only allow the client to process the final result, and not stdout
along the wayGonna go with an EventEmitter
here. It can handle both task completion, and individual command completion elegantly. Gunter will export an emitter
object that client's can use to listen for events emitted by exec
to communicate its state.
I really lazily implemented two of
.exec
's private function,localTask
andremoteTask
, which take care of running commands locally and against some server respectively.They're implemented synchronously, meaning that Gunter will wait around for a task to finish before
.exec
eventually returns eitherfalse
if it errors or the task object that was executed if successful.Instead, they should be implemented asynchronously, since this is the whole reason I implemented this as a Node.js package instead of some Sinatra API or something. They should execute tasks in the background, and call some callback function when complete, of the form
callback(error, task)
, wherecallback(error)
is called if there's an error, andcallback(null, task)
is called if the task is executed with no errors.