File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -109,9 +109,14 @@ def terminated?
109
109
@terminated . set?
110
110
end
111
111
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.
113
114
def terminate!
114
115
guard!
116
+ @children . each do |ch |
117
+ ch . send ( :core ) . tap { |core | core . send ( :schedule_execution ) { core . terminate! } }
118
+ end
119
+
115
120
@terminated . set
116
121
117
122
@parent_core . remove_child reference if @parent_core
@@ -120,7 +125,6 @@ def terminate!
120
125
log DEBUG , "rejected #{ envelope . message } from #{ envelope . sender_path } "
121
126
end
122
127
@mailbox . clear
123
- # TODO terminate all children
124
128
125
129
nil
126
130
end
Original file line number Diff line number Diff line change @@ -163,6 +163,30 @@ def assert condition
163
163
end
164
164
end
165
165
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
+
166
190
end
167
191
end
168
192
end
You can’t perform that action at this time.
0 commit comments