Class: Reacto::Operations::Merge
- Inherits:
-
Object
- Object
- Reacto::Operations::Merge
- Defined in:
- lib/reacto/operations/merge.rb
Instance Method Summary collapse
- #call(tracker) ⇒ Object
-
#initialize(trackables, delay_error: false) ⇒ Merge
constructor
A new instance of Merge.
Constructor Details
#initialize(trackables, delay_error: false) ⇒ Merge
Returns a new instance of Merge.
7 8 9 10 11 12 13 14 |
# File 'lib/reacto/operations/merge.rb', line 7 def initialize(trackables, delay_error: false) @trackables = trackables @close_notifications = Concurrent::AtomicFixnum.new(@trackables.size + 1) @lock = Mutex.new @delay_error = delay_error end |
Instance Method Details
#call(tracker) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/reacto/operations/merge.rb', line 16 def call(tracker) error = nil close = -> () do @lock.synchronize do if @close_notifications.decrement == 0 error.nil? ? tracker.on_close : tracker.on_error(error) end end end err = if @delay_error -> (er) do @lock.synchronize do error = er tracker.on_error(error) if @close_notifications.decrement == 0 end end else tracker.method(:on_error) end sub = Subscriptions::OperationSubscription.new( tracker, close: close, error: err ) @trackables.each { |trackable| trackable.send(:do_track, sub) } sub end |