Skip to content

Commit 99e2a26

Browse files
committed
ActorContext#post now supresses exceptions thrown in the callback block.
1 parent 2336b6f commit 99e2a26

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/concurrent/simple_actor_ref.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ def run_message_loop
9999
ensure
100100
now = Time.now
101101
message.ivar.complete(ex.nil?, result, ex)
102-
message.callback.call(now, result, ex) if message.callback
102+
103+
begin
104+
message.callback.call(now, result, ex) if message.callback
105+
rescue @exception_class => ex
106+
# suppress
107+
end
108+
103109
observers.notify_observers(now, message.payload, result, ex)
104110
end
105111
end

spec/concurrent/actor_ref_shared.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ def receive(*msg)
115115
expected_value.should be_nil
116116
expected_reason.should be_a StandardError
117117
end
118+
119+
it 'supresses exceptions thrown by the callback' do
120+
expected = nil
121+
subject.post(:foo){|time, value, reason| raise StandardError }
122+
sleep(0.1)
123+
124+
subject.post(:bar){|time, value, reason| expected = value }
125+
sleep(0.1)
126+
127+
expected.should eq :bar
128+
end
118129
end
119130

120131
context '#post!' do

0 commit comments

Comments
 (0)