Class: Async::Container::Channel
- Inherits:
-
Object
- Object
- Async::Container::Channel
- Defined in:
- lib/async/container/channel.rb
Instance Attribute Summary collapse
-
#in ⇒ Object
readonly
Returns the value of attribute in.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
Instance Method Summary collapse
- #close ⇒ Object
- #close_read ⇒ Object
- #close_write ⇒ Object
-
#initialize ⇒ Channel
constructor
A new instance of Channel.
- #receive ⇒ Object
Constructor Details
#initialize ⇒ Channel
Returns a new instance of Channel.
28 29 30 |
# File 'lib/async/container/channel.rb', line 28 def initialize @in, @out = ::IO.pipe end |
Instance Attribute Details
#in ⇒ Object (readonly)
Returns the value of attribute in.
32 33 34 |
# File 'lib/async/container/channel.rb', line 32 def in @in end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
33 34 35 |
# File 'lib/async/container/channel.rb', line 33 def out @out end |
Instance Method Details
#close ⇒ Object
43 44 45 46 |
# File 'lib/async/container/channel.rb', line 43 def close close_read close_write end |
#close_read ⇒ Object
35 36 37 |
# File 'lib/async/container/channel.rb', line 35 def close_read @in.close end |
#close_write ⇒ Object
39 40 41 |
# File 'lib/async/container/channel.rb', line 39 def close_write @out.close end |
#receive ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/async/container/channel.rb', line 48 def receive if data = @in.gets begin return JSON.parse(data, symbolize_names: true) rescue return {line: data} end end end |