Class: Reacto::Operations::Cycle

Inherits:
Object
  • Object
show all
Defined in:
lib/reacto/operations/cycle.rb

Instance Method Summary collapse

Constructor Details

#initialize(behaviour, n = nil) ⇒ Cycle

Returns a new instance of Cycle.



6
7
8
9
# File 'lib/reacto/operations/cycle.rb', line 6

def initialize(behaviour, n = nil)
  @behaviour = behaviour
  @n = n
end

Instance Method Details

#call(tracker) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/reacto/operations/cycle.rb', line 11

def call(tracker)

  close = -> do
    if @n.nil? || @n > 1
      next_n = @n.nil? ? @n : @n - 1
      @behaviour.call(self.class.new(@behaviour, next_n).call(tracker))
    else
      tracker.on_close
    end
  end

  Subscriptions::OperationSubscription.new(tracker, close: close)
end