Class: ConcurrentWorker::IPCDuplexChannel
- Inherits:
-
Object
- Object
- ConcurrentWorker::IPCDuplexChannel
- Defined in:
- lib/concurrent_worker/common.rb
Instance Method Summary collapse
- #choose_io ⇒ Object
- #close ⇒ Object
-
#initialize ⇒ IPCDuplexChannel
constructor
A new instance of IPCDuplexChannel.
- #recv ⇒ Object
- #send(obj) ⇒ Object
Constructor Details
#initialize ⇒ IPCDuplexChannel
Returns a new instance of IPCDuplexChannel.
47 48 49 50 51 |
# File 'lib/concurrent_worker/common.rb', line 47 def initialize @p_pid = Process.pid @p2c = IO.pipe('ASCII-8BIT', 'ASCII-8BIT') @c2p = IO.pipe('ASCII-8BIT', 'ASCII-8BIT') end |
Instance Method Details
#choose_io ⇒ Object
53 54 55 56 57 |
# File 'lib/concurrent_worker/common.rb', line 53 def choose_io w_pipe, r_pipe = @p_pid == Process.pid ? [@p2c, @c2p] : [@c2p, @p2c] @wio, @rio = w_pipe[1], r_pipe[0] [w_pipe[0], r_pipe[1]].map(&:close) end |
#close ⇒ Object
73 74 75 |
# File 'lib/concurrent_worker/common.rb', line 73 def close [@wio, @rio].map(&:close) end |
#recv ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/concurrent_worker/common.rb', line 65 def recv begin Marshal.load(@rio) rescue IOError raise StopIteration end end |
#send(obj) ⇒ Object
59 60 61 62 63 |
# File 'lib/concurrent_worker/common.rb', line 59 def send(obj) begin Marshal.dump(obj, @wio) end end |