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

0 commit comments

Comments
 (0)