Class: Async::Wrapper
- Inherits:
-
Object
- Object
- Async::Wrapper
- Defined in:
- lib/async/wrapper.rb
Overview
Represents an asynchronous IO within a reactor.
Defined Under Namespace
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
The underlying native
io. -
#monitor ⇒ Object
readonly
The monitor for this wrapper, if any.
-
#reactor ⇒ Object
The reactor this wrapper is associated with, if any.
Instance Method Summary collapse
-
#close ⇒ Object
Close the io and monitor.
- #closed? ⇒ Boolean
-
#initialize(io, reactor = nil) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #resume(*args) ⇒ Object
-
#wait_any(duration = nil) ⇒ Object
Wait fo the io to become either readable or writable.
-
#wait_readable(duration = nil) ⇒ Object
Wait for the io to become readable.
-
#wait_writable(duration = nil) ⇒ Object
Wait for the io to become writable.
Constructor Details
#initialize(io, reactor = nil) ⇒ Wrapper
Returns a new instance of Wrapper.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/async/wrapper.rb', line 41 def initialize(io, reactor = nil) @io = io @reactor = reactor @monitor = nil @readable = nil @writable = nil @any = nil end |
Instance Attribute Details
#io ⇒ Object (readonly)
The underlying native io.
69 70 71 |
# File 'lib/async/wrapper.rb', line 69 def io @io end |
#monitor ⇒ Object (readonly)
The monitor for this wrapper, if any.
75 76 77 |
# File 'lib/async/wrapper.rb', line 75 def monitor @monitor end |
#reactor ⇒ Object
The reactor this wrapper is associated with, if any.
72 73 74 |
# File 'lib/async/wrapper.rb', line 72 def reactor @reactor end |
Instance Method Details
#close ⇒ Object
Close the io and monitor.
134 135 136 137 138 |
# File 'lib/async/wrapper.rb', line 134 def close cancel_monitor @io.close end |
#closed? ⇒ Boolean
140 141 142 |
# File 'lib/async/wrapper.rb', line 140 def closed? @io.closed? end |
#resume(*args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/async/wrapper.rb', line 52 def resume(*args) readiness = @monitor.readiness if @readable and (readiness == :r or readiness == :rw) @readable.resume(*args) end if @writable and (readiness == :w or readiness == :rw) @writable.resume(*args) end if @any @any.resume(*args) end end |
#wait_any(duration = nil) ⇒ Object
Wait fo the io to become either readable or writable.
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/async/wrapper.rb', line 119 def wait_any(duration = nil) raise WaitError if @any self.reactor = Task.current.reactor begin @any = Fiber.current wait_for(duration) ensure @any = nil @monitor.interests = interests if @monitor end end |
#wait_readable(duration = nil) ⇒ Object
Wait for the io to become readable.
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/async/wrapper.rb', line 88 def wait_readable(duration = nil) raise WaitError if @readable self.reactor = Task.current.reactor begin @readable = Fiber.current wait_for(duration) ensure @readable = nil @monitor.interests = interests if @monitor end end |
#wait_writable(duration = nil) ⇒ Object
Wait for the io to become writable.
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/async/wrapper.rb', line 103 def wait_writable(duration = nil) raise WaitError if @writable self.reactor = Task.current.reactor begin @writable = Fiber.current wait_for(duration) ensure @writable = nil @monitor.interests = interests if @monitor end end |