Class: Core::Async::Collection
- Inherits:
-
Object
- Object
- Core::Async::Collection
- Extended by:
- Is::Async
- Includes:
- Enumerable, Is::Async
- Defined in:
- lib/core/async/collection.rb
Class Method Summary collapse
-
.build(object) ⇒ Object
- public
-
Builds a collection from an enumerable object.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
(also: #add)
- public
-
Adds a value to the collection.
-
#each ⇒ Object
- public
-
Yields each resolved value.
-
#initialize(values = []) ⇒ Collection
constructor
A new instance of Collection.
Methods included from Is::Async
Constructor Details
#initialize(values = []) ⇒ Collection
Returns a new instance of Collection.
42 43 44 45 46 47 48 |
# File 'lib/core/async/collection.rb', line 42 def initialize(values = []) unless values.respond_to?(:each) raise ArgumentError, "values are not enumerable" end @values = values end |
Class Method Details
.build(object) ⇒ Object
- public
-
Builds a collection from an enumerable object.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/core/async/collection.rb', line 13 def build(object) aware do errored, stopped = false values = object.map { |value| break if errored || stopped async do if block_given? yield value else value end rescue LocalJumpError stopped = true rescue => error errored = true raise error end } new(values) if values end end |
Instance Method Details
#<<(value) ⇒ Object Also known as: add
- public
-
Adds a value to the collection.
52 53 54 |
# File 'lib/core/async/collection.rb', line 52 def <<(value) @values << value end |
#each ⇒ Object
- public
-
Yields each resolved value.
59 60 61 62 63 64 65 |
# File 'lib/core/async/collection.rb', line 59 def each return to_enum(:each) unless block_given? @values.each do |value| yield resolve(value) end end |