Class: Core::Async::Enumerator
- Inherits:
-
Object
- Object
- Core::Async::Enumerator
- Includes:
- Enumerable, Is::Async, Is::Inspectable
- 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
Constructor Details
#initialize(object) ⇒ Enumerator
Returns a new instance of Enumerator.
14 15 16 17 18 19 20 |
# File 'lib/core/async/enumerator.rb', line 14 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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/core/async/enumerator.rb', line 24 def each unless block_given? return to_enum(:each) end errored = false stopped = false futures = [] @object.each do |value| break if errored || stopped futures << async do yield value rescue LocalJumpError stopped = true rescue => error errored = true raise error end end futures.each(&:wait) end |