Method: Concurrent::AtomicDirectUpdate#update

Defined in:
lib/concurrent/atomic_reference/direct_update.rb

#update {|Object| ... } ⇒ Object

Pass the current value to the given block, replacing it with the block’s result. May retry if the value changes during the block’s execution.

Yields:

  • (Object)

    Calculate a new value for the atomic reference using given (old) value

Yield Parameters:

  • old_value (Object)

    the starting value of the atomic reference

Returns:

  • the new value



19
20
21
22
# File 'lib/concurrent/atomic_reference/direct_update.rb', line 19

def update
  true until compare_and_set(old_value = get, new_value = yield(old_value))
  new_value
end