Class: Reacto::Operations::Throttle

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

Instance Method Summary collapse

Constructor Details

#initialize(delay) ⇒ Throttle

Returns a new instance of Throttle.



8
9
10
11
12
13
14
# File 'lib/reacto/operations/throttle.rb', line 8

def initialize(delay)
  @delay = delay
  @last = NO_VALUE
  @ready = false
  @error = NO_VALUE
  @close = false
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
# File 'lib/reacto/operations/throttle.rb', line 16

def call(tracker)
  close = -> () { @close = true }
  error = -> (e) do
    delay_task(tracker) unless @ready
    @error = e
  end
  value = -> (v) do
    delay_task(tracker) unless @ready
    @last = v
  end

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