Skip to content

Commit a7dc6b1

Browse files
committed
AtomicReference: add note about try_update API
1 parent 28f89b9 commit a7dc6b1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/concurrent/atomic_reference/direct_update.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def update
3333
# given (old) value
3434
# @yieldparam [Object] old_value the starting value of the atomic reference
3535
#
36+
# @note This method was altered to avoid raising an exception by default.
37+
# Instead, this method now returns `nil` in case of failure. For more info,
38+
# please see: https://github.com/ruby-concurrency/concurrent-ruby/pull/336
39+
#
3640
# @return [Object] the new value, or nil if update failed
3741
def try_update
3842
old_value = get
@@ -53,6 +57,11 @@ def try_update
5357
# given (old) value
5458
# @yieldparam [Object] old_value the starting value of the atomic reference
5559
#
60+
# @note This behavior mimics the behavior of the original
61+
# `AtomicReference#try_update` API. The reason this was changed was to
62+
# avoid raising exceptions (which are inherently slow) by default. For more
63+
# info: https://github.com/ruby-concurrency/concurrent-ruby/pull/336
64+
#
5665
# @return [Object] the new value
5766
#
5867
# @raise [Concurrent::ConcurrentUpdateError] if the update fails

0 commit comments

Comments
 (0)