Method: Timeloop#loop
- Defined in:
- lib/timeloop.rb
#loop ⇒ Object
Runs provided block periodically.
Yields Integer index of the iteration to the provide block every ‘period`.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/timeloop.rb', line 11 def loop i = -1 super() do run_started_at = Time.now i += 1 logger.debug("#{to_s}: starting #{i}th run") yield(i) if block_given? break if i+1 >= max sleep til_next_start_time(Time.now - run_started_at) .tap{|s| logger.debug "#{to_s}: sleeping #{s} seconds until next run" } end end |