Changeset 617
- Timestamp:
- 12/13/07 19:48:35 (1 year ago)
- Files:
-
- version_0/lib/em/processes.rb (modified) (1 diff)
- version_0/tests/test_processes.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
version_0/lib/em/processes.rb
r616 r617 26 26 27 27 module EventMachine 28 29 # EM::DeferrableChildProcess is a sugaring of a common use-case 30 # involving EM::popen. 31 # Call the #open method on EM::DeferrableChildProcess, passing 32 # a command-string. #open immediately returns an EM::Deferrable 33 # object. It also schedules the forking of a child process, which 34 # will execute the command passed to #open. 35 # When the forked child terminates, the Deferrable will be signalled 36 # and execute its callbacks, passing the data that the child process 37 # wrote to stdout. 38 # 28 39 class DeferrableChildProcess < EventMachine::Connection 29 40 include EventMachine::Deferrable 30 41 42 # Sugars a common use-case involving forked child processes. 43 # #open takes a String argument containing an shell command 44 # string (including arguments if desired). #open immediately 45 # returns an EventMachine::Deferrable object, without blocking. 46 # 47 # It also invokes EventMachine#popen to run the passed-in 48 # command in a forked child process. 49 # 50 # When the forked child terminates, the Deferrable that 51 # #open calls its callbacks, passing the data returned 52 # from the child process. 53 # 31 54 def self.open cmd 32 55 EventMachine.popen( cmd, DeferrableChildProcess ) version_0/tests/test_processes.rb
r616 r617 30 30 class TestProcesses < Test::Unit::TestCase 31 31 32 # EM::DeferrableChildProcess is a sugaring of a common use-case 33 # involving EM::popen. 34 # Call the #open method on EM::DeferrableChildProcess, passing 35 # a command-string. #open immediately returns an EM::Deferrable 36 # object. It also schedules the forking of a child process, which 37 # will execute the command passed to #open. 38 # When the forked child terminates, the Deferrable will be signalled 39 # and execute its callbacks, passing the data that the child process 40 # wrote to stdout. 41 # 32 42 def test_deferrable_child_process 33 43 ls = "" 34 44 EM.run { 35 d = EM::DeferrableChildProcess.open( "ls " )45 d = EM::DeferrableChildProcess.open( "ls -ltr" ) 36 46 d.callback {|data_from_child| 37 47 ls = data_from_child
