Skip to content

Commit 5a2235e

Browse files
authored
Merge pull request #533 from faucct/master
Concurrent::Atom#swap fixed: reraise the exceptions from block
2 parents 13c6202 + c5073a0 commit 5a2235e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/concurrent/atom.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ def swap(*args)
158158

159159
loop do
160160
old_value = value
161+
new_value = yield(old_value, *args)
161162
begin
162-
new_value = yield(old_value, *args)
163163
break old_value unless valid?(new_value)
164164
break new_value if compare_and_set(old_value, new_value)
165165
rescue

spec/concurrent/atom_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ module Concurrent
151151

152152
expect(counter.value).to be > 1
153153
end
154+
155+
it 'reraises the exception from block' do
156+
atom = Atom.new(0)
157+
expect do
158+
atom.swap do |value|
159+
fail 'something went wrong'
160+
end
161+
end.to raise_error 'something went wrong'
162+
end
154163
end
155164

156165
context '#reset' do

0 commit comments

Comments
 (0)