class Concurrent::IVar

def add_observer(observer = nil, func = :update, &block)

Parameters:
  • func (Symbol) -- symbol naming the method to call when this `Observable` has changes`
  • observer (Object) -- the object that will be notified of changes
def add_observer(observer = nil, func = :update, &block)
  raise ArgumentError.new('cannot provide both an observer and a block') if observer && block
  direct_notification = false
  if block
    observer = block
    func = :call
  end
  mutex.synchronize do
    if event.set?
      direct_notification = true
    else
      observers.add_observer(observer, func)
    end
  end
  observer.send(func, Time.now, self.value, reason) if direct_notification
  observer
end

def complete(success, value, reason)

def complete(success, value, reason)
  mutex.synchronize do
    raise MultipleAssignmentError.new('multiple assignment') if [:fulfilled, :rejected].include? @state
    set_state(success, value, reason)
    event.set
  end
  time = Time.now
  observers.notify_and_delete_observers{ [time, self.value, reason] }
  self
end

def fail(reason = StandardError.new)

def fail(reason = StandardError.new)
  complete(false, nil, reason)
end

def initialize(value = NO_VALUE, opts = {})

Options Hash: (**opts)
  • :copy_on_deref (String) -- call the given `Proc` passing the internal value and
  • :freeze_on_deref (String) -- call `#freeze` before returning the data
  • :dup_on_deref (String) -- call `#dup` before returning the data

Parameters:
  • opts (Hash) -- the options to create a message with
  • value (Object) -- the initial value
def initialize(value = NO_VALUE, opts = {})
  init_obligation
  self.observers = CopyOnWriteObserverSet.new
  set_deref_options(opts)
  if value == NO_VALUE
    @state = :pending
  else
    set(value)
  end
end

def set(value)

def set(value)
  complete(true, value, nil)
end