Module: Async::App::TimerComponent::InstanceMethods

Defined in:
lib/async/app/timer_component.rb

Instance Method Summary collapse

Instance Method Details

#init!Object



10
11
12
13
# File 'lib/async/app/timer_component.rb', line 10

def init!
  super
  @timer = Async::Timer.new(run_on_start:, start: false, on_error: method(:on_error)) { tick! }
end

#restart!Object



34
35
36
37
# File 'lib/async/app/timer_component.rb', line 34

def restart!
  @timer.restart(interval)
  info { "Restarted. Polling interval=#{interval}" }
end

#run!Object



15
16
17
18
19
20
# File 'lib/async/app/timer_component.rb', line 15

def run!
  return if @timer.active?

  @timer.start(interval)
  info { "Started. Interval = #{interval}" }
end

#stop!Object



22
23
24
25
# File 'lib/async/app/timer_component.rb', line 22

def stop!
  @timer&.stop
  super
end

#tick!Object

TimerComponent - specific methods



28
29
30
31
32
# File 'lib/async/app/timer_component.rb', line 28

def tick!
  debug { "Started" }
  on_tick
  debug { "Finished" }
end