Class: Charming::Internal::TimerControl

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/internal/timer_control.rb

Overview

TimerControl is the runtime-injected surface that lets ephemeral controllers start and stop the EventLoop's scheduled timers by name (the same pattern as Application#task_executor). bindings is a callable returning the current route's timer bindings, so navigation needs no re-wiring.

Defined Under Namespace

Classes: Null

Instance Method Summary collapse

Constructor Details

#initialize(event_loop:, bindings:) ⇒ TimerControl

Returns a new instance of TimerControl.



10
11
12
13
# File 'lib/charming/internal/timer_control.rb', line 10

def initialize(event_loop:, bindings:)
  @event_loop = event_loop
  @bindings = bindings
end

Instance Method Details

#running?(name) ⇒ Boolean

True while the named timer is scheduled.

Returns:

  • (Boolean)


29
30
31
# File 'lib/charming/internal/timer_control.rb', line 29

def running?(name)
  @event_loop.timer_running?(name.to_sym)
end

#start(name) ⇒ Object

Schedules the named declared timer on the event loop.

Raises:

  • (ArgumentError)


16
17
18
19
20
21
# File 'lib/charming/internal/timer_control.rb', line 16

def start(name)
  binding = @bindings.call[name.to_sym]
  raise ArgumentError, "unknown timer #{name.to_sym.inspect}" unless binding

  @event_loop.start_timer(binding)
end

#stop(name) ⇒ Object

Unschedules the named timer.



24
25
26
# File 'lib/charming/internal/timer_control.rb', line 24

def stop(name)
  @event_loop.stop_timer(name.to_sym)
end