Method: Concurrent::TimerTask#initialize

Defined in:
lib/concurrent-ruby/concurrent/timer_task.rb

#initialize(opts = {}) {|task| ... } ⇒ TimerTask

Create a new TimerTask with the given task and configuration.

Parameters:

  • opts (Hash) (defaults to: {})

    the options defining task execution.

Options Hash (opts):

  • :execution_interval (Float)

    number of seconds between task executions (default: EXECUTION_INTERVAL)

  • :run_now (Boolean)

    Whether to run the task immediately upon instantiation or to wait until the first # execution_interval has passed (default: false)

  • executor, (Executor)

    default is global_io_executor

  • :dup_on_deref (Boolean) — default: false

    Call #dup before returning the data from Concern::Dereferenceable#value

  • :freeze_on_deref (Boolean) — default: false

    Call #freeze before returning the data from Concern::Dereferenceable#value

  • :copy_on_deref (Proc) — default: nil

    When calling the Concern::Dereferenceable#value method, call the given proc passing the internal value as the sole argument then return the new value returned from the proc.

Yields:

  • to the block after :execution_interval seconds have passed since the last yield

Yield Parameters:

  • task

    a reference to the TimerTask instance so that the block can control its own lifecycle. Necessary since self will refer to the execution context of the block rather than the running TimerTask.

Raises:

  • ArgumentError when no block is given.



210
211
212
213
214
# File 'lib/concurrent-ruby/concurrent/timer_task.rb', line 210

def initialize(opts = {}, &task)
  raise ArgumentError.new('no block given') unless block_given?
  super
  set_deref_options opts
end