class Concurrent::Atom
def swap(*args)
-
(ArgumentError)
- When no block is given.
Returns:
-
(Object)
- The final value of the atom after all operations and
Other tags:
- Yieldreturn: - The intended new value of the atom.
Other tags:
- Yieldparam: args - All arguments passed to the function, in order.
Yieldparam: value - The current value of the atom.
Other tags:
- Yield: - Calculates a new value for the atom based on the
Parameters:
-
args
(Object
) -- Zero or more arguments passed to the block.
Other tags:
- Note: - The given block may be called multiple times, and thus should be free
def swap(*args) raise ArgumentError.new('no block given') unless block_given? loop do old_value = value new_value = yield(old_value, *args) begin break old_value unless valid?(new_value) break new_value if compare_and_set(old_value, new_value) rescue break old_value end end end