@@ -33,6 +33,7 @@ class Core
33
33
# @option opts [Context] actor_class a class to be instantiated defining Actor's behaviour
34
34
# @option opts [Array<Object>] args arguments for actor_class instantiation
35
35
# @option opts [Executor] executor, default is `Concurrent.configuration.global_task_pool`
36
+ # @option opts [true, false] link, atomically link the actor to its parent
36
37
# @option opts [IVar, nil] initialized, if present it'll be set or failed after {Context} initialization
37
38
# @option opts [Proc, nil] logger a proc accepting (level, progname, message = nil, &block) params,
38
39
# can be used to hook actor instance to any logging system
@@ -69,11 +70,18 @@ def initialize(opts = {}, &block)
69
70
args = opts . fetch ( :args , [ ] )
70
71
initialized = Type! opts [ :initialized ] , IVar , NilClass
71
72
73
+ messages = [ ]
74
+ messages << :link if opts [ :link ]
75
+
72
76
schedule_execution do
73
77
begin
74
78
@context . send :initialize_core , self
75
79
@context . send :initialize , *args , &block
76
80
81
+ messages . each do |message |
82
+ handle_envelope Envelope . new ( message , nil , parent , reference )
83
+ end
84
+
77
85
initialized . set true if initialized
78
86
rescue => ex
79
87
log ERROR , ex
@@ -117,10 +125,7 @@ def remove_child(child)
117
125
# can be called from other alternative Reference implementations
118
126
# @param [Envelope] envelope
119
127
def on_envelope ( envelope )
120
- schedule_execution do
121
- log DEBUG , "received #{ envelope . message . inspect } from #{ envelope . sender } "
122
- @first_behaviour . on_envelope envelope
123
- end
128
+ schedule_execution { handle_envelope envelope }
124
129
nil
125
130
end
126
131
@@ -178,6 +183,13 @@ def behaviour(klass)
178
183
def behaviour! ( klass )
179
184
@behaviours . fetch klass
180
185
end
186
+
187
+ private
188
+
189
+ def handle_envelope ( envelope )
190
+ log DEBUG , "received #{ envelope . message . inspect } from #{ envelope . sender } "
191
+ @first_behaviour . on_envelope envelope
192
+ end
181
193
end
182
194
end
183
195
end
0 commit comments