Class: IO::Event::Selector::Select::Waiter
- Inherits:
-
Struct
- Object
- Struct
- IO::Event::Selector::Select::Waiter
- Defined in:
- lib/io/event/selector/select.rb
Overview
A linked list node used to track fibers waiting for IO events.
Instance Attribute Summary collapse
-
#events ⇒ Object
Returns the value of attribute events.
-
#fiber ⇒ Object
Returns the value of attribute fiber.
-
#tail ⇒ Object
Returns the value of attribute tail.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#dispatch(events, &reactivate) ⇒ Object
Dispatch the given events to the list of waiting fibers.
-
#each(&block) ⇒ Object
Iterate over each active waiting fiber and its requested events.
-
#invalidate ⇒ Object
Clear the waiting fiber so it will not be resumed.
Instance Attribute Details
#events ⇒ Object
Returns the value of attribute events
125 126 127 |
# File 'lib/io/event/selector/select.rb', line 125 def events @events end |
#fiber ⇒ Object
Returns the value of attribute fiber
125 126 127 |
# File 'lib/io/event/selector/select.rb', line 125 def fiber @fiber end |
#tail ⇒ Object
Returns the value of attribute tail
125 126 127 |
# File 'lib/io/event/selector/select.rb', line 125 def tail @tail end |
Instance Method Details
#alive? ⇒ Boolean
127 128 129 |
# File 'lib/io/event/selector/select.rb', line 127 def alive? self.fiber&.alive? end |
#dispatch(events, &reactivate) ⇒ Object
Dispatch the given events to the list of waiting fibers. If the fiber was not waiting for the given events, it is reactivated by calling the given block.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/io/event/selector/select.rb', line 132 def dispatch(events, &reactivate) # We capture the tail here, because calling reactivate might modify it: tail = self.tail if fiber = self.fiber if fiber.alive? revents = events & self.events if revents.zero? reactivate.call(self) else self.fiber = nil fiber.transfer(revents) end else self.fiber = nil end end tail&.dispatch(events, &reactivate) end |
#each(&block) ⇒ Object
Iterate over each active waiting fiber and its requested events.
159 160 161 162 163 164 165 |
# File 'lib/io/event/selector/select.rb', line 159 def each(&block) if fiber = self.fiber yield fiber, self.events end self.tail&.each(&block) end |
#invalidate ⇒ Object
Clear the waiting fiber so it will not be resumed.
154 155 156 |
# File 'lib/io/event/selector/select.rb', line 154 def invalidate self.fiber = nil end |