File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ def self.current
145
145
Thread . current [ :__current_actor__ ]
146
146
end
147
147
148
- # implements ROOT
148
+ # implements the root actor
149
149
class Root
150
150
include Context
151
151
# to allow spawning of new actors, spawn needs to be called inside the parent Actor
@@ -158,8 +158,12 @@ def on_message(message)
158
158
end
159
159
end
160
160
161
+ @root = Delay . new { Core . new ( parent : nil , name : '/' , class : Root ) . reference }
162
+
161
163
# A root actor, a default parent of all actors spawned outside an actor
162
- ROOT = Core . new ( parent : nil , name : '/' , class : Root ) . reference
164
+ def self . root
165
+ @root . value
166
+ end
163
167
164
168
# Spawns a new actor.
165
169
#
@@ -184,7 +188,7 @@ def self.spawn(*args, &block)
184
188
if Actress . current
185
189
Core . new ( spawn_optionify ( *args ) . merge ( parent : Actress . current ) , &block ) . reference
186
190
else
187
- ROOT . ask ( [ :spawn , spawn_optionify ( *args ) , block ] ) . value
191
+ root . ask ( [ :spawn , spawn_optionify ( *args ) , block ] ) . value
188
192
end
189
193
end
190
194
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ class Core
17
17
# @return [String] the name of this instance, it should be uniq (not enforced right now)
18
18
# @!attribute [r] path
19
19
# @return [String] a path of this actor. It is used for easier orientation and logging.
20
- # Path is constructed recursively with: `parent.path + self.name` up to a {Actress::ROOT },
20
+ # Path is constructed recursively with: `parent.path + self.name` up to a {Actress.root },
21
21
# e.g. `/an_actor/its_child`.
22
22
# (It will also probably form a supervision path (failures will be reported up to parents)
23
23
# in future versions.)
Original file line number Diff line number Diff line change @@ -67,14 +67,14 @@ def on_message(message)
67
67
actor = Ping . spawn :ping , queue
68
68
69
69
# when spawn returns children are set
70
- Concurrent ::Actress :: ROOT . send ( :core ) . instance_variable_get ( :@children ) . should include ( actor )
70
+ Concurrent ::Actress . root . send ( :core ) . instance_variable_get ( :@children ) . should include ( actor )
71
71
72
72
actor << 'a' << 1
73
73
queue . pop . should eq 'a'
74
74
actor . ask ( 2 ) . value . should eq 2
75
75
76
- actor . parent . should eq Concurrent ::Actress :: ROOT
77
- Concurrent ::Actress :: ROOT . path . should eq '/'
76
+ actor . parent . should eq Concurrent ::Actress . root
77
+ Concurrent ::Actress . root . path . should eq '/'
78
78
actor . path . should eq '/ping'
79
79
child = actor . ask ( :child ) . value
80
80
child . path . should eq '/ping/pong'
@@ -105,7 +105,7 @@ def on_message(message)
105
105
subject &subject_definition
106
106
after { terminate_actors subject }
107
107
its ( :path ) { should eq '/ping' }
108
- its ( :parent ) { pending ( 'intermittent JRuby deadlock' ) ; should eq ROOT }
108
+ its ( :parent ) { pending ( 'intermittent JRuby deadlock' ) ; should eq Actress . root }
109
109
its ( :name ) { should eq 'ping' }
110
110
it ( 'executor should be global' ) { subject . executor . should eq Concurrent . configuration . global_task_pool }
111
111
its ( :reference ) { should eq subject }
You can’t perform that action at this time.
0 commit comments