Class: EventMachine::DeferrableChildProcess

Inherits:
Connection
  • Object
show all
Includes:
Deferrable
Defined in:
lib/em/processes.rb

Overview

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.

Constant Summary

Constants included from Deferrable

EventMachine::Deferrable::Pool

Class Method Summary collapse

Methods included from Deferrable

#callback, #cancel_callback, #cancel_errback, #cancel_timeout, #errback, #fail, future, #set_deferred_status, #succeed, #timeout

Methods inherited from Connection

#close_connection, #close_connection_after_writing, #comm_inactivity_timeout, #comm_inactivity_timeout=, #connection_completed, #detach, #error?, #get_idle_time, #get_peer_cert, #get_peername, #get_pid, #get_proxied_bytes, #get_sock_opt, #get_sockname, #get_status, #notify_readable=, #notify_readable?, #notify_writable=, #notify_writable?, #pause, #paused?, #pending_connect_timeout, #pending_connect_timeout=, #post_init, #proxy_completed, #proxy_incoming_to, #proxy_target_unbound, #reconnect, #resume, #send_data, #send_datagram, #send_file_data, #set_sock_opt, #ssl_handshake_completed, #ssl_verify_peer, #start_tls, #stop_proxying, #stream_file_data

Class Method Details

.open(cmd) ⇒ Object

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.



60
61
62
# File 'lib/em/processes.rb', line 60

def self.open cmd
  EventMachine.popen( cmd, DeferrableChildProcess )
end