Module: EventMachine

Defined in:
lib/em/stdout.rb

Defined Under Namespace

Classes: Stdout

Class Method Summary collapse

Class Method Details

.split_stdoutObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/em/stdout.rb', line 5

def split_stdout
  stdout = nil
  EM.next_tick do
    stdout, read, write = STDOUT.clone, *IO.pipe
    EM.attach(read, Stdout) do |connection|
      connection.stdout = stdout
      yield connection if block_given?
    end
    STDOUT.reopen(write)
  end
  sleep(0.01) until stdout
  stdout
end