Class: DeferrableGratification::Combinators::Join Abstract
- Inherits:
-
DefaultDeferrable
- Object
- DefaultDeferrable
- DeferrableGratification::Combinators::Join
- Defined in:
- lib/deferrable_gratification/combinators/join.rb
Overview
Subclasses should override #done? to define whether they wait for some or all of the operations to complete, and #finish to define what they do when #done? returns true.
Abstract base class for combinators that depend on a number of asynchronous operations (potentially executing in parallel).
Direct Known Subclasses
Defined Under Namespace
Classes: FirstSuccess, Sentinel, Successes
Class Method Summary collapse
-
.setup!(*operations) ⇒ Join
Create a Join and register the callbacks.
Instance Method Summary collapse
-
#initialize(*operations) ⇒ Join
constructor
Prepare to wait for the completion of
operations
. -
#setup! ⇒ Object
Register callbacks and errbacks on the supplied operations to notify this Join of completion.
Constructor Details
#initialize(*operations) ⇒ Join
Prepare to wait for the completion of operations
.
Does not actually set up any callbacks or errbacks: call #setup! for that.
19 20 21 22 23 |
# File 'lib/deferrable_gratification/combinators/join.rb', line 19 def initialize(*operations) @operations = operations @successes = Array.new(@operations.size, Sentinel.new) @failures = Array.new(@operations.size, Sentinel.new) end |
Class Method Details
.setup!(*operations) ⇒ Join
Create a DeferrableGratification::Combinators::Join and register the callbacks.
47 48 49 |
# File 'lib/deferrable_gratification/combinators/join.rb', line 47 def self.setup!(*operations) new(*operations).tap(&:setup!) end |
Instance Method Details
#setup! ⇒ Object
Register callbacks and errbacks on the supplied operations to notify this DeferrableGratification::Combinators::Join of completion.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/deferrable_gratification/combinators/join.rb', line 27 def setup! finish if done? @operations.each_with_index do |op, index| op.callback do |result| @successes[index] = result finish if done? end op.errback do |error| @failures[index] = error finish if done? end end end |