class Phoenix::Timer
- Phoenix::Timer
- Reference
- Object
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.crConstructors
-
.new(callback : -> , delay : UInt32, repeat : Bool = false)
Create a basic timer with a fixed delay
-
.new(callback : -> , delay_calc : UInt32 -> UInt32, repeat : Bool = false)
Create a dynamic timer with a delay based on the count
Instance Method Summary
-
#reset
Cancels any previous
#schedule_timeout
and resets the count -
#schedule_timeout
Cancels any previous
#schedule_timeout
and schedules callback
Constructor Detail
def self.new(callback : -> , delay : UInt32, repeat : Bool = false)
#
Create a basic timer with a fixed delay
def self.new(callback : -> , delay_calc : UInt32 -> UInt32, repeat : Bool = false)
#
Create a dynamic timer with a delay based on the count