Skip to content

Commit 4636ff6

Browse files
committed
Added #on_error callback to ActorContext.
1 parent 99e2a26 commit 4636ff6

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/concurrent/actor_context.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def on_reset
1313
def on_shutdown
1414
end
1515

16+
def on_error(time, message, exception)
17+
end
18+
1619
def self.included(base)
1720

1821
class << base

lib/concurrent/simple_actor_ref.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def run_message_loop
9595
begin
9696
result = @actor.receive(*message.payload)
9797
rescue @exception_class => ex
98+
@actor.on_error(Time.now, message.payload, ex)
9899
@actor.on_reset if @reset_on_error
99100
ensure
100101
now = Time.now

spec/concurrent/actor_ref_shared.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,24 @@ def receive(*msg)
231231
end
232232
end
233233

234+
context '#on_error' do
235+
236+
specify 'is not called on success' do
237+
actor = subject.instance_variable_get(:@actor)
238+
actor.should_not_receive(:on_error).with(any_args)
239+
subject.post(:foo)
240+
sleep(0.1)
241+
end
242+
243+
specify 'is called when a message raises an exception' do
244+
actor = subject.instance_variable_get(:@actor)
245+
actor.should_receive(:on_error).
246+
with(anything, [:poison], an_instance_of(StandardError))
247+
subject.post(:poison)
248+
sleep(0.1)
249+
end
250+
end
251+
234252
context 'observation' do
235253

236254
let(:observer_class) do

0 commit comments

Comments
 (0)