class Phoenix::Timer

Overview

Creates a timer that accepts a delay_calc proc to perform calculated timeout retries, such as exponential backoff.

reconnect_timer = Phoenix::Timer.new(
  ->{ connect() },
  ->(count : UInt32) { [1000_u32, 5000_u32, 10_000_u32].fetch(count - 1) { 10_000_u32 } }
)
reconnect_timer.schedule_timeout # fires after 1000
reconnect_timer.schedule_timeout # fires after 5000
reconnect_timer.reset
reconnect_timer.schedule_timeout # fires after 1000

Defined in:

phoenix/timer.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(callback : -> , delay : UInt32, repeat : Bool = false) #

Create a basic timer with a fixed delay


[View source]
def self.new(callback : -> , delay_calc : UInt32 -> UInt32, repeat : Bool = false) #

Create a dynamic timer with a delay based on the count


[View source]

Instance Method Detail

def reset #

Cancels any previous #schedule_timeout and resets the count


[View source]
def schedule_timeout #

Cancels any previous #schedule_timeout and schedules callback


[View source]