Skip to content

Commit 8d64ed1

Browse files
committed
Terminate all children on parent termination
1 parent bd65cd7 commit 8d64ed1

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/concurrent/actress/core.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,14 @@ def terminated?
109109
@terminated.set?
110110
end
111111

112-
# Terminates the actor, any Envelope received after termination is rejected
112+
# Terminates the actor. Any Envelope received after termination is rejected.
113+
# Terminates all its children, does not wait until they are terminated.
113114
def terminate!
114115
guard!
116+
@children.each do |ch|
117+
ch.send(:core).tap { |core| core.send(:schedule_execution) { core.terminate! } }
118+
end
119+
115120
@terminated.set
116121

117122
@parent_core.remove_child reference if @parent_core
@@ -120,7 +125,6 @@ def terminate!
120125
log DEBUG, "rejected #{envelope.message} from #{envelope.sender_path}"
121126
end
122127
@mailbox.clear
123-
# TODO terminate all children
124128

125129
nil
126130
end

spec/concurrent/actress_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,30 @@ def assert condition
163163
end
164164
end
165165

166+
describe 'termination' do
167+
subject do
168+
AdHoc.spawn(:parent) do
169+
child = AdHoc.spawn(:child) { -> v { v } }
170+
-> v do
171+
if v == :terminate
172+
terminate!
173+
else
174+
child
175+
end
176+
end
177+
end
178+
end
179+
180+
it 'terminates with all its children' do
181+
child = subject.ask! :child
182+
subject.terminated?.should be_false
183+
subject.ask(:terminate).wait
184+
subject.terminated?.should be_true
185+
child.terminated.wait
186+
child.terminated?.should be_true
187+
end
188+
end
189+
166190
end
167191
end
168192
end

0 commit comments

Comments
 (0)