Skip to content

Commit b17d3bd

Browse files
committed
Merge pull request #443 from ruby-concurrency/fix-agent-await-bug
Fixed bug in which Agent#await triggered a validation failure.
2 parents 6a76967 + 42847fe commit b17d3bd

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/concurrent/agent.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,9 @@ def execute_next_job
545545
new_value = job.action.call(old_value, *job.args)
546546
@caller.value = nil
547547

548-
if new_value != AWAIT_FLAG && ns_validate(new_value)
548+
return if new_value == AWAIT_FLAG
549+
550+
if ns_validate(new_value)
549551
@current.value = new_value
550552
observers.notify_observers(Time.now, old_value, new_value)
551553
else

spec/concurrent/agent_spec.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,16 @@ def update(time, old_value, new_value)
800800
expect(subject.value).to eq expected
801801
end
802802

803+
it 'does not trigger the error mode' do
804+
subject = Agent.new(10)
805+
subject.send{ |x| sleep(0.1); x + 1 }
806+
subject.await_for(1)
807+
808+
expect(subject.value).to eq 11
809+
expect(subject).to_not be_failed
810+
expect(subject.error).to be nil
811+
end
812+
803813
it 'does not trigger observers' do
804814
observer_class = Class.new do
805815
attr_reader :count
@@ -989,7 +999,7 @@ def update(time, old_value, new_value)
989999
subject.send_via(executor){ sleep(1) }
9901000
5.times{ subject.send_via(executor){ nil } }
9911001
expect {
992-
subject.await_for!(0.1)
1002+
subject.await_for!(0.1)
9931003
}.to raise_error(Concurrent::TimeoutError)
9941004
end
9951005

@@ -1004,7 +1014,7 @@ def update(time, old_value, new_value)
10041014
t = Thread.new{ subject.restart(42, clear_actions: true) }
10051015

10061016
expect {
1007-
subject.await_for!(0.2)
1017+
subject.await_for!(0.2)
10081018
}.to raise_error(Concurrent::TimeoutError)
10091019
end
10101020
end

0 commit comments

Comments
 (0)