Class | Hydra::Pipe |
In: |
lib/hydra/pipe.rb
|
Parent: | Object |
Read and write between two processes via pipes. For example:
@pipe = Hydra::Pipe.new @child = Process.fork do @pipe.identify_as_child puts "A message from my parent:\n#{@pipe.gets.text}" @pipe.close end @pipe.identify_as_parent @pipe.write Hydra::Messages::TestMessage.new(:text => "Hello!") @pipe.close
Note that the TestMessage class is only available in tests, and not in Hydra by default.
When the process forks, the pipe is copied. When a pipe is identified as a parent or child, it is choosing which ends of the pipe to use.
A pipe is actually two pipes:
Parent == Pipe 1 ==> Child Parent <== Pipe 2 == Child
It‘s like if you had two cardboard tubes and you were using them to drop balls with messages in them between processes. One tube is for sending from parent to child, and the other tube is for sending from child to parent.