Class: MPThreads::Channel
- Inherits:
-
Object
- Object
- MPThreads::Channel
- Defined in:
- lib/multiprocess-threads.rb
Overview
Creates one way channel
Instance Method Summary collapse
-
#initialize ⇒ Channel
constructor
A new instance of Channel.
- #read ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize ⇒ Channel
Returns a new instance of Channel.
10 11 12 |
# File 'lib/multiprocess-threads.rb', line 10 def initialize @read_io, @write_io = IO.pipe end |
Instance Method Details
#read ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/multiprocess-threads.rb', line 14 def read @write_io.close unless @write_io.closed? data = @read_io.gets return nil unless data Marshal.load data # rubocop:disable Security/MarshalLoad end |
#write(data) ⇒ Object
22 23 24 25 |
# File 'lib/multiprocess-threads.rb', line 22 def write(data) @read_io.close unless @read_io.closed? @write_io << "#{Marshal.dump(data)}#{$RS}" end |