class Movie::Scheduler

Overview

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

Defined in:

movie/scheduler.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(dispatcher : Dispatcher) #

[View source]

Instance Method Detail

def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def stop : Nil #

[View source]