Method: Concurrent::IVar#initialize

Defined in:
lib/concurrent/ivar.rb

#initialize(value = NULL, opts = {}, &block) ⇒ IVar

Create a new ‘IVar` in the `:pending` state with the (optional) initial value.

Parameters:

  • value (Object) (defaults to: NULL)

    the initial value

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

    the options to create a message with

Options Hash (opts):

  • :dup_on_deref (String) — default: false

    call ‘#dup` before returning the data

  • :freeze_on_deref (String) — default: false

    call ‘#freeze` before returning the data

  • :copy_on_deref (String) — default: nil

    call the given ‘Proc` passing the internal value and returning the value returned from the proc



61
62
63
64
65
66
67
# File 'lib/concurrent/ivar.rb', line 61

def initialize(value = NULL, opts = {}, &block)
  if value != NULL && block_given?
    raise ArgumentError.new('provide only a value or a block')
  end
  super(&nil)
  synchronize { ns_initialize(value, opts, &block) }
end