Class: EM::HyperDex::Client::EnumerableDeferrable
- Inherits:
-
Completion
- Object
- Completion
- EM::HyperDex::Client::EnumerableDeferrable
- Defined in:
- lib/em-hyperdex-client.rb
Overview
Define a set of other Enumerable methods that can be usefully
used asynchronously (if there are any), like perhaps #map
,
#inject
, etc.
A deferrable that can be enumerated.
This is a really freaky kind of a deferrable. It accepts the usual
callback
and errback
blocks, but it also has a special #each
callback, which will cause the block provided for each item in the
search result set. Once the result set has been enumerated, the
callback
will be called.
Instance Method Summary collapse
-
#each {|item| ... } ⇒ Object
Define a block to call for each item in the result set.
-
#initialize(iter) ⇒ EnumerableDeferrable
constructor
private
Create a new EnumerableDeferrable.
-
#item_available(val = NoValue) ⇒ Object
private
Trigger whenever we know there's an item available.
Constructor Details
#initialize(iter) ⇒ EnumerableDeferrable
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new EnumerableDeferrable
291 292 293 294 295 |
# File 'lib/em-hyperdex-client.rb', line 291 def initialize(iter) @iter = iter @items = [] super() end |
Instance Method Details
#each {|item| ... } ⇒ Object
Define a block to call for each item in the result set.
303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/em-hyperdex-client.rb', line 303 def each(&blk) return Enumeration.new(self) unless block_given? if state == :succeeded @items.each { |i| blk.call(i) } else @each_block = blk end self end |
#item_available(val = NoValue) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Trigger whenever we know there's an item available.
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/em-hyperdex-client.rb', line 319 def item_available(val = NoValue) if val == NoValue val = @iter.next end if val.nil? self.succeed else if @each_block begin @each_block.call(val) rescue Exception => ex fail(ex) end else @items << val end end end |