Class: ConcurrentRails::Multi
- Inherits:
-
Object
- Object
- ConcurrentRails::Multi
- Defined in:
- lib/concurrent_rails/multi.rb
Class Method Summary collapse
Instance Method Summary collapse
- #complete? ⇒ Boolean
- #compute ⇒ Object
- #compute! ⇒ Object
- #enqueue ⇒ Object
- #errors ⇒ Object
-
#initialize(actions, executor) ⇒ Multi
constructor
A new instance of Multi.
Constructor Details
#initialize(actions, executor) ⇒ Multi
Returns a new instance of Multi.
11 12 13 14 15 |
# File 'lib/concurrent_rails/multi.rb', line 11 def initialize(actions, executor) @actions = actions @executor = executor @exceptions = Concurrent::Array.new end |
Class Method Details
.enqueue(*actions, executor: :io) ⇒ Object
5 6 7 8 9 |
# File 'lib/concurrent_rails/multi.rb', line 5 def self.enqueue(*actions, executor: :io) raise ArgumentError, "#enqueue accepts `Proc`s only" unless actions.all?(Proc) new(actions, executor).enqueue end |
Instance Method Details
#complete? ⇒ Boolean
35 36 37 |
# File 'lib/concurrent_rails/multi.rb', line 35 def complete? futures.all?(&:complete?) end |
#compute ⇒ Object
27 28 29 |
# File 'lib/concurrent_rails/multi.rb', line 27 def compute futures.map(&:value) end |
#compute! ⇒ Object
31 32 33 |
# File 'lib/concurrent_rails/multi.rb', line 31 def compute! futures.map(&:value!) end |
#enqueue ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/concurrent_rails/multi.rb', line 17 def enqueue @futures = actions.map do |action| f = ConcurrentRails::Future.new(executor: executor, &action) f.add_observer(self) f.execute end self end |
#errors ⇒ Object
39 40 41 |
# File 'lib/concurrent_rails/multi.rb', line 39 def errors @exceptions end |