Timers/Intervals in Crystal Lang

For timeout there's delay. Please be aware that the API for this isn't finalized and might get changed in a future release or even temporarily removed again.

For interval there's currently nothing that guarantees exact timings, but if that's no concern and an approximate interval is enough it's as simple to do as

spawn do
  loop do
    sleep INTERVAL
    do_regular_work
  end
end

sleep # Or some other workload, when the main fiber quits so will the program and thus all other fibers.

Tags:

Crystal Lang