Skip to content

Commit 6ed9e81

Browse files
committed
Remove supervised behavior
Linking is enough, Supervised was just making things complicated.
1 parent 1b96989 commit 6ed9e81

File tree

13 files changed

+37
-116
lines changed

13 files changed

+37
-116
lines changed

doc/actor/define.in.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def on_event(event)
2929
end
3030
end #
3131

32-
an_actor = AnActor.spawn name: 'an_actor', args: 10, supervise: true #
32+
an_actor = AnActor.spawn name: 'an_actor', args: 10 #
3333
an_actor << Message.new(:add, 1) << Message.new(:subtract, 2) #
3434
an_actor.ask!(Message.new(:value, nil))
3535
an_actor << :boo << Message.new(:add, 1) #

doc/actor/define.out.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def on_event(event)
2929
end
3030
end
3131

32-
an_actor = AnActor.spawn name: 'an_actor', args: 10, supervise: true
32+
an_actor = AnActor.spawn name: 'an_actor', args: 10
3333
an_actor << Message.new(:add, 1) << Message.new(:subtract, 2)
3434
an_actor.ask!(Message.new(:value, nil)) # => 9
3535
an_actor << :boo << Message.new(:add, 1)

doc/actor/init.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
require 'concurrent/actor'
2-
Concurrent::Actor.i_know_it_is_experimental!

doc/actor/io.in.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def default_executor
3333
end #
3434

3535
pool = Concurrent::Actor::Utils::Pool.spawn('pool', 2) do |balancer, index|
36-
IOWorker.spawn(name: "worker-#{index}", supervise: true, args: [balancer])
36+
IOWorker.spawn(name: "worker-#{index}", args: [balancer])
3737
end
3838

3939
pool << 1 << 2 << 3 << 4 << 5 << 6

doc/actor/io.out.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def default_executor
3535
end
3636

3737
pool = Concurrent::Actor::Utils::Pool.spawn('pool', 2) do |balancer, index|
38-
IOWorker.spawn(name: "worker-#{index}", supervise: true, args: [balancer])
38+
IOWorker.spawn(name: "worker-#{index}", args: [balancer])
3939
end
4040
# => #<Concurrent::Actor::Reference:0x7fd6451ecaf8 /pool (Concurrent::Actor::Utils::Pool)>
4141

doc/actor/messaging.out.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def on_message(message)
2525
end
2626

2727
calculator = Calculator.spawn('calculator')
28-
# => #<Concurrent::Actor::Reference:0x7fd646110700 /calculator (Calculator)>
28+
# => #<Concurrent::Actor::Reference:0x7fb94a2565d8 /calculator (Calculator)>
2929
calculator.ask! Add[1, 2] # => 3
3030
calculator.ask! Subtract[1, 0.5] # => 0.5
3131
calculator << :terminate!
32-
# => #<Concurrent::Actor::Reference:0x7fd646110700 /calculator (Calculator)>
32+
# => #<Concurrent::Actor::Reference:0x7fb94a2565d8 /calculator (Calculator)>

doc/actor/quick.in.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ def on_message(message)
1414
end
1515
end #
1616

17-
# `supervise: true` makes the actor supervised by root actor
18-
adder = Adder.spawn(name: :adder, supervise: true, args: [1])
17+
# `link: true` makes the actor linked to root actor and supervised
18+
# which is default behavior
19+
adder = Adder.spawn(name: :adder, link: true, args: [1])
1920
adder.parent
2021

2122
# tell and forget
22-
adder.tell(:add) << :add
23+
adder.tell(:add).tell(:add)
2324
# ask to get result
2425
adder.ask!(:add)
2526
# fail the actor

doc/actor/quick.out.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ def on_message(message)
1414
end
1515
end
1616

17-
# `supervise: true` makes the actor supervised by root actor
18-
adder = Adder.spawn(name: :adder, supervise: true, args: [1])
19-
# => #<Concurrent::Actor::Reference:0x7fd64420ac48 /adder (Adder)>
17+
# `link: true` makes the actor linked to root actor and supervised
18+
# which is default behavior
19+
adder = Adder.spawn(name: :adder, link: true, args: [1])
20+
# => #<Concurrent::Actor::Reference:0x7fb94bb30040 /adder (Adder)>
2021
adder.parent
2122
# => #<Concurrent::Actor::Reference:0x7fd644229008 / (Concurrent::Actor::Root)>
2223

2324
# tell and forget
24-
adder.tell(:add) << :add
25-
# => #<Concurrent::Actor::Reference:0x7fd64420ac48 /adder (Adder)>
25+
adder.tell(:add).tell(:add)
26+
# => #<Concurrent::Actor::Reference:0x7fb94bb30040 /adder (Adder)>
2627
# ask to get result
2728
adder.ask!(:add) # => 4
2829
# fail the actor

lib/concurrent/actor/behaviour.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ module Behaviour
6464
require 'concurrent/actor/behaviour/pausing'
6565
require 'concurrent/actor/behaviour/removes_child'
6666
require 'concurrent/actor/behaviour/sets_results'
67-
require 'concurrent/actor/behaviour/supervised'
6867
require 'concurrent/actor/behaviour/supervising'
6968
require 'concurrent/actor/behaviour/termination'
7069
require 'concurrent/actor/behaviour/terminates_children'
@@ -126,8 +125,7 @@ def self.linking
126125

127126
# @see '' its source code
128127
def self.supervised
129-
[[Supervised, []],
130-
[Pausing, []]]
128+
[[Pausing, []]]
131129
end
132130

133131
# @see '' its source code

lib/concurrent/actor/behaviour/linking.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
# TODO track what is linked, clean when :terminated
5+
# send :linked/:unlinked messages back to build the array of linked actors
46

57
# Links the actor to other actors and sends actor's events to them,
68
# like: `:terminated`, `:paused`, `:resumed`, errors, etc.
@@ -41,11 +43,11 @@ class Linking < Abstract
4143
def initialize(core, subsequent, core_options)
4244
super core, subsequent, core_options
4345
@linked = Set.new
44-
if core_options[:link] != false || core_options[:supervise] != false
45-
@linked.add Actor.current
46-
end
46+
@linked.add Actor.current if core_options[:link] != false
4747
end
4848

49+
# TODO also handle :linked_actors returning array
50+
4951
def on_envelope(envelope)
5052
case envelope.message
5153
when :link

lib/concurrent/actor/behaviour/supervised.rb

Lines changed: 0 additions & 83 deletions
This file was deleted.

lib/concurrent/actor/core.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class Core
3737
# @option opts [Array<Object>] args arguments for actor_class instantiation
3838
# @option opts [Executor] executor, default is `Concurrent.configuration.global_task_pool`
3939
# @option opts [true, false] link, atomically link the actor to its parent (default: true)
40-
# @option opts [true, false] supervise, atomically supervise the actor by its parent (default: true)
4140
# @option opts [Class] reference a custom descendant of {Reference} to use
4241
# @option opts [Array<Array(Behavior::Abstract, Array<Object>)>] behaviour_definition, array of pairs
4342
# where each pair is behaviour class and its args, see {Behaviour.basic_behaviour_definition}

spec/concurrent/actor_spec.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def on_message(message)
280280
end
281281

282282
describe 'pausing' do
283-
it 'pauses on error' do
283+
it 'pauses on error and resumes' do
284284
queue = Queue.new
285285
resuming_behaviour = Behaviour.restarting_behaviour_definition(:resume!)
286286

@@ -291,30 +291,32 @@ def on_message(message)
291291
-> m { m == :add ? 1 : pass }
292292
end
293293

294-
actor << :supervise
295-
queue << actor.ask!(:supervisor)
294+
actor << :link
295+
queue << actor.ask!(:linked?)
296296
actor << nil
297297
queue << actor.ask(:add)
298298

299299
-> m { queue << m }
300300
end
301301

302302
expect(queue.pop).to eq :init
303-
expect(queue.pop).to eq test
303+
expect(queue.pop).to eq true
304304
expect(queue.pop.value).to eq 1
305305
expect(queue.pop).to eq :resumed
306306
terminate_actors test
307+
end
307308

309+
it 'pauses on error and resets' do
310+
queue = Queue.new
308311
test = AdHoc.spawn name: :tester,
309312
behaviour_definition: Behaviour.restarting_behaviour_definition do
310313
actor = AdHoc.spawn name: :pausing,
311-
supervise: true,
312314
behaviour_definition: Behaviour.restarting_behaviour_definition do
313315
queue << :init
314316
-> m { m == :object_id ? self.object_id : pass }
315317
end
316318

317-
queue << actor.ask!(:supervisor)
319+
queue << actor.ask!(:linked?)
318320
queue << actor.ask!(:object_id)
319321
actor << nil
320322
queue << actor.ask(:object_id)
@@ -325,14 +327,16 @@ def on_message(message)
325327
end
326328

327329
expect(queue.pop).to eq :init
328-
expect(queue.pop).to eq test
330+
expect(queue.pop).to eq true
329331
first_id = queue.pop
330332
second_id = queue.pop.value
331333
expect(first_id).not_to eq second_id # context already reset
332334
expect(queue.pop).to eq :init # rebuilds context
333335
expect(queue.pop).to eq :reset
334336
terminate_actors test
337+
end
335338

339+
it 'pauses on error and restarts' do
336340
queue = Queue.new
337341
resuming_behaviour = Behaviour.restarting_behaviour_definition.map do |c, args|
338342
if Behaviour::Supervising == c
@@ -349,8 +353,8 @@ def on_message(message)
349353
-> m { m == :add ? 1 : pass }
350354
end
351355

352-
actor << :supervise
353-
queue << actor.ask!(:supervisor)
356+
actor << :link
357+
queue << actor.ask!(:linked?)
354358
actor << nil
355359
queue << actor.ask(:add)
356360

@@ -360,7 +364,7 @@ def on_message(message)
360364
end
361365

362366
expect(queue.pop).to eq :init
363-
expect(queue.pop).to eq test
367+
expect(queue.pop).to eq true
364368
expect(queue.pop.wait.reason).to be_a_kind_of(ActorTerminated)
365369
expect(queue.pop).to eq :init
366370
expect(queue.pop).to eq :restarted
@@ -378,7 +382,7 @@ def work(message)
378382
end
379383

380384
pool = Concurrent::Actor::Utils::Pool.spawn! 'pool', 5 do |balancer, index|
381-
worker.spawn name: "worker-#{index}", supervise: true, args: [balancer]
385+
worker.spawn name: "worker-#{index}", args: [balancer]
382386
end
383387

384388
expect(pool.ask!(5)).to eq 10

0 commit comments

Comments
 (0)