Sha256: 0752364dfda6109362a45708a550b1cfac2972f3296b8287fdf1c8b80f37d90d
Contents?: true
Size: 822 Bytes
Versions: 8
Compression:
Stored size: 822 Bytes
Contents
require 'concurrent/atomic_reference/concurrent_update_error' module Concurrent # Define update methods that delegate to @ref field class Atomic # 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. def update true until @ref.compare_and_set(old_value = @ref.get, new_value = yield(old_value)) new_value end def try_update old_value = @ref.get new_value = yield old_value unless @ref.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 end end
Version data entries
8 entries across 8 versions & 1 rubygems