module Concurrent::AtomicDirectUpdate

def try_update!

Raises:
  • (Concurrent::ConcurrentUpdateError) - if the update fails

Returns:
  • (Object) - the new value

Other tags:
    Note: - This behavior mimics the behavior of the original

Other tags:
    Yieldparam: old_value - the starting value of the atomic reference

Other tags:
    Yield: - Calculate a new value for the atomic reference using
def try_update!
  old_value = get
  new_value = yield old_value
  unless compare_and_set(old_value, new_value)
    if $VERBOSE
      raise ConcurrentUpdateError, "Update failed"
    else
      raise ConcurrentUpdateError, "Update failed", ConcurrentUpdateError::CONC_UP_ERR_BACKTRACE
    end
  end
  new_value
end