Class: MultiProcess::Receiver

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_process/receiver.rb

Overview

Can handle input from multiple processes and run custom actions on event and output.

Direct Known Subclasses

Logger, NilReceiver, StringReceiver

Instance Method Summary collapse

Instance Method Details

#message(process, name, message) ⇒ Object

Send a custom messages.



33
34
35
# File 'lib/multi_process/receiver.rb', line 33

def message(process, name, message)
  received process, name, message
end

#pipe(process, name) ⇒ Object

Request a new pipe writer for given process and name.

Parameters:

  • process (Process)

    Process requesting pipe.

  • name (Symbol)

    Name associated to pipe e.g. ‘:out` or `:err`.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/multi_process/receiver.rb', line 14

def pipe(process, name)
  reader, writer = IO.pipe

  Loop.instance.watch(reader) do |action, monitor|
    case action
      when :registered
        connected(process, name)
      when :ready
        received(process, name, read(monitor.io))
      when :eof
        removed(process, name)
    end
  end

  writer
end