Module: Timeloop::Helper

Included in:
Timeloop
Defined in:
lib/timeloop.rb

Overview

Conveniences methods that provide access to the Timeloop functionality to be included in other classes and modules.

Instance Method Summary collapse

Instance Method Details

#every(period, opts = {}, &blk) ⇒ Object

Provides a way to execute a block of code periodically. The runtime of the block is taken in to account so a delay in one run does not impact the start times of future runs.

Arguments

period - seconds or name of time period (eg,
         'second', 'hour') between iterations

Options

max     - the maximum number of executions of the block. Default:
          INFINITY
maximum - synonym of `max`
logger  - logger to which debugging info should be sent. Default:
          no logging

Yields Integer index of the iteration to the provide block every ‘period`.



113
114
115
# File 'lib/timeloop.rb', line 113

def every(period, opts = {}, &blk)
  Timeloop.new(opts.merge(period: period)).loop(&blk)
end