Module: Prosody::State::Scanning
- Included in:
- DequeState, MapState, PublishedDeque, PublishedMap
- Defined in:
- lib/prosody/state.rb,
sig/state.rbs
Overview
Shared native-scan driving mixed into the traversal handles.
Instance Method Summary collapse
-
#scan_each(direction, opener = :scan) ⇒ void
Opens a native scan in
direction, yields each item, and closes the scan viaensureon stop or exception. - #scan_items(scan) ⇒ void
Instance Method Details
#scan_each(direction, opener = :scan) ⇒ void
This method returns an undefined value.
Opens a native scan in direction, yields each item, and closes the
scan via ensure on stop or exception. Direction validity is enforced
by the native layer (an invalid token is rejected transient there); the
public traversal methods only ever pass :forward/:backward. opener
selects the native cursor seam — the default :scan yields values (or
[key, value] pairs), :keys yields bare map keys.
216 217 218 |
# File 'lib/prosody/state.rb', line 216 def scan_each(direction, opener = :scan) scan_items(@native.public_send(opener, direction)) { |item| yield item } end |
#scan_items(scan) ⇒ void
This method returns an undefined value.
220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/prosody/state.rb', line 220 def scan_items(scan) # `nil` is the exhaustion sentinel (unambiguous under the null ban); # terminate on it explicitly rather than on falsiness, so a legal # stored `false` (or a `[key, false]` pair, always a truthy Array) # does not stop iteration and drop the tail after it. until (item = scan.next).nil? yield item end ensure scan.close end |