EM::DeferrableChildProcess is a sugaring of a common use-case involving EM::popen. Call the open method on EM::DeferrableChildProcess, passing a command-string. open immediately returns an EM::Deferrable object. It also schedules the forking of a child process, which will execute the command passed to open. When the forked child terminates, the Deferrable will be signalled and execute its callbacks, passing the data that the child process wrote to stdout.
@private
# File lib/em/processes.rb, line 43 def initialize super @data = [] end
Sugars a common use-case involving forked child processes. open takes a String argument containing an shell command string (including arguments if desired). open immediately returns an EventMachine::Deferrable object, without blocking.
It also invokes EventMachine#popen to run the passed-in command in a forked child process.
When the forked child terminates, the Deferrable that open calls its callbacks, passing the data returned from the child process.
# File lib/em/processes.rb, line 60 def self.open cmd EventMachine.popen( cmd, DeferrableChildProcess ) end
@private
# File lib/em/processes.rb, line 65 def receive_data data @data << data end
@private
# File lib/em/processes.rb, line 70 def unbind succeed( @data.join ) end