Class: Async::Wrapper
- Inherits:
-
Object
- Object
- Async::Wrapper
- Defined in:
- lib/async/wrapper.rb
Overview
Represents an asynchronous IO within a reactor.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(io, task) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #monitor(interests) ⇒ Object
- #wait_any(interests = :rw) ⇒ Object
- #wait_readable ⇒ Object
- #wait_writable ⇒ Object
Constructor Details
#initialize(io, task) ⇒ Wrapper
Returns a new instance of Wrapper.
24 25 26 27 28 |
# File 'lib/async/wrapper.rb', line 24 def initialize(io, task) @io = io @task = task @monitor = nil end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
30 31 32 |
# File 'lib/async/wrapper.rb', line 30 def io @io end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
31 32 33 |
# File 'lib/async/wrapper.rb', line 31 def task @task end |
Instance Method Details
#close ⇒ Object
66 67 68 69 |
# File 'lib/async/wrapper.rb', line 66 def close @monitor.close if @monitor @monitor = nil end |
#monitor(interests) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/async/wrapper.rb', line 33 def monitor(interests) unless @monitor @monitor = @task.register(@io, interests) else @monitor.interests = interests end @monitor.value = Fiber.current yield ensure @monitor.value = nil if @monitor end |
#wait_any(interests = :rw) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/async/wrapper.rb', line 56 def wait_any(interests = :rw) monitor(interests) do # Async.logger.debug "Fiber #{Fiber.current} yielding..." result = Fiber.yield # Async.logger.debug "Fiber #{Fiber.current} resuming with result #{result}..." raise result if result.is_a? Exception end end |
#wait_readable ⇒ Object
48 49 50 |
# File 'lib/async/wrapper.rb', line 48 def wait_readable wait_any(:r) end |
#wait_writable ⇒ Object
52 53 54 |
# File 'lib/async/wrapper.rb', line 52 def wait_writable wait_any(:w) end |