Class: Core::Async::Enumerator
- Inherits:
-
Object
- Object
- Core::Async::Enumerator
- Includes:
- Enumerable, Is::Async
- Defined in:
- lib/core/async/enumerator.rb
Instance Method Summary collapse
-
#each ⇒ Object
- public
-
Yields each value within its own async context, waiting on the enumeration to complete.
-
#initialize(object) ⇒ Enumerator
constructor
A new instance of Enumerator.
Methods included from Is::Async
#async, #await, #aware, #defer, #resolve, #sleep, #timeout
Constructor Details
#initialize(object) ⇒ Enumerator
Returns a new instance of Enumerator.
11 12 13 14 15 16 17 |
# File 'lib/core/async/enumerator.rb', line 11 def initialize(object) unless object.respond_to?(:each) raise ArgumentError, "object is not enumerable" end @object = object end |
Instance Method Details
#each ⇒ Object
- public
-
Yields each value within its own async context, waiting on the enumeration to complete.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/core/async/enumerator.rb', line 21 def each unless block_given? return to_enum(:each) end await do errored = false @object.each do |value| break if errored async { begin yield value rescue => error errored = true raise error ensure defer end } end end end |