class EventMachine::DeferrableChildProcess

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.

Public Class Methods

new() click to toggle source

@private

Calls superclass method EventMachine::Connection.new
# File lib/em/processes.rb, line 43
def initialize
  super
  @data = []
end
open(cmd) click to toggle source

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

Public Instance Methods

receive_data(data) click to toggle source

@private

# File lib/em/processes.rb, line 65
def receive_data data
  @data << data
end
unbind() click to toggle source

@private

# File lib/em/processes.rb, line 70
def unbind
  succeed( @data.join )
end