class

Movie::Scheduler

Inherits Reference < Object

Centralized scheduler for managing timers within the actor system. Provides cancellable one-shot timers that execute callbacks after a delay. Uses the actor system's dispatcher for proper fiber management.

Example:

handle = scheduler.schedule_once(5.seconds) do
  puts "Timer fired!"
end
handle.cancel  # Cancels the timer if not yet fired

Constructors

new(dispatcher : Dispatcher)
Source

Instance methods

schedule_message(delay : Time::Span, target : ActorRef(T), message : T) : TimerHandle forall T

Schedules a one-shot timer that sends a message to an actor after the given delay. Returns a TimerHandle that can be used to cancel the timer.

Source
schedule_once(delay : Time::Span, &block : -> Nil) : TimerHandle

Schedules a one-shot timer that executes the block after the given delay. Returns a TimerHandle that can be used to cancel the timer before it fires.

If the timer is cancelled before the delay expires, the block will not be executed. If the timer has already fired, cancellation has no effect.

Source
schedule_system_message(delay : Time::Span, target : ActorRefBase, message : SystemMessage) : TimerHandle

Schedules a one-shot timer that sends a system message to an actor after the given delay. Returns a TimerHandle that can be used to cancel the timer.

Source