Skip to content

Commit 916e92a

Browse files
committed
AtomicMarkableReference: update try_update/try_update! APIs
1 parent 53c0422 commit 916e92a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/concurrent/edge/atomic_markable_reference.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def update
119119
end
120120
end
121121

122-
# @!macro [attach] atomic_markable_reference_method_try_update
122+
# @!macro [attach] atomic_markable_reference_method_try_update!
123123
#
124124
# Pass the current value to the given block, replacing it
125125
# with the block's result. Raise an exception if the update
@@ -133,7 +133,7 @@ def update
133133
# @return [ImmutableArray] the new value and marked state
134134
#
135135
# @raise [Concurrent::ConcurrentUpdateError] if the update fails
136-
def try_update
136+
def try_update!
137137
old_val, old_mark = @Reference.get
138138
new_val, new_mark = yield old_val, old_mark
139139

@@ -147,7 +147,7 @@ def try_update
147147
ImmutableArray[new_val, new_mark]
148148
end
149149

150-
# @!macro [attach] atomic_markable_reference_method_try_update_no_exception
150+
# @!macro [attach] atomic_markable_reference_method_try_update
151151
#
152152
# Pass the current value to the given block, replacing it with the
153153
# block's result. Simply return nil if update fails.
@@ -159,7 +159,7 @@ def try_update
159159
#
160160
# @return [ImmutableArray] the new value and marked state, or nil if
161161
# the update failed
162-
def try_update_no_exception
162+
def try_update
163163
old_val, old_mark = @Reference.get
164164
new_val, new_mark = yield old_val, old_mark
165165

spec/concurrent/atomic/atomic_markable_reference_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
end
2727
end
2828

29-
describe '#try_update' do
29+
describe '#try_update!' do
3030
it 'updates the value and mark' do
31-
val, mark = subject.try_update { |v, m| [v + 1, !m] }
31+
val, mark = subject.try_update! { |v, m| [v + 1, !m] }
3232

3333
expect(subject.value).to eq 1001
3434
expect(val).to eq 1001
@@ -37,15 +37,15 @@
3737

3838
it 'raises ConcurrentUpdateError when attempting to set inside of block' do
3939
expect do
40-
subject.try_update do |v, m|
40+
subject.try_update! do |v, m|
4141
subject.set(1001, false)
4242
[v + 1, !m]
4343
end
4444
end.to raise_error Concurrent::ConcurrentUpdateError
4545
end
4646
end
4747

48-
describe '#try_update_no_exception' do
48+
describe '#try_update' do
4949
it 'updates the value and mark' do
5050
val, mark = subject.try_update { |v, m| [v + 1, !m] }
5151

0 commit comments

Comments
 (0)