Method: Concurrent::AtomicMarkableReference#try_update

Defined in:
lib/concurrent-ruby/concurrent/atomic/atomic_markable_reference.rb

#try_update {|Object| ... } ⇒ Array

Pass the current value to the given block, replacing it with the block’s result. Simply return nil if update fails.

the update failed

Yields:

  • (Object)

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

Yield Parameters:

  • old_val (Object)

    the starting value of the atomic reference

  • old_mark (Boolean)

    the starting state of marked

Returns:

  • (Array)

    the new value and marked state, or nil if



152
153
154
155
156
157
158
159
# File 'lib/concurrent-ruby/concurrent/atomic/atomic_markable_reference.rb', line 152

def try_update
  old_val, old_mark = reference
  new_val, new_mark = yield old_val, old_mark

  return unless compare_and_set old_val, new_val, old_mark, new_mark

  immutable_array(new_val, new_mark)
end