module Async::Loop
def self.quantized(interval: 60, &block)
- Example: Run every 5 minutes aligned to the hour: -
Example: Run every minute at :00 seconds: -
def self.quantized(interval: 60, &block) while true # Compute the wait time to the next interval: wait = interval - (Time.now.to_f % interval) if wait.positive? # Sleep until the next interval boundary: sleep(wait) end begin yield rescue => error Console.error(self, "Loop error:", error) end end end