@@ -33,6 +33,7 @@ class Core
3333 # @option opts [Context] actor_class a class to be instantiated defining Actor's behaviour
3434 # @option opts [Array<Object>] args arguments for actor_class instantiation
3535 # @option opts [Executor] executor, default is `Concurrent.configuration.global_task_pool`
36+ # @option opts [true, false] link, atomically link the actor to its parent
3637 # @option opts [IVar, nil] initialized, if present it'll be set or failed after {Context} initialization
3738 # @option opts [Proc, nil] logger a proc accepting (level, progname, message = nil, &block) params,
3839 # can be used to hook actor instance to any logging system
@@ -69,11 +70,18 @@ def initialize(opts = {}, &block)
6970 args = opts . fetch ( :args , [ ] )
7071 initialized = Type! opts [ :initialized ] , IVar , NilClass
7172
73+ messages = [ ]
74+ messages << :link if opts [ :link ]
75+
7276 schedule_execution do
7377 begin
7478 @context . send :initialize_core , self
7579 @context . send :initialize , *args , &block
7680
81+ messages . each do |message |
82+ handle_envelope Envelope . new ( message , nil , parent , reference )
83+ end
84+
7785 initialized . set true if initialized
7886 rescue => ex
7987 log ERROR , ex
@@ -117,10 +125,7 @@ def remove_child(child)
117125 # can be called from other alternative Reference implementations
118126 # @param [Envelope] envelope
119127 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 }
124129 nil
125130 end
126131
@@ -178,6 +183,13 @@ def behaviour(klass)
178183 def behaviour! ( klass )
179184 @behaviours . fetch klass
180185 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
181193 end
182194 end
183195end
0 commit comments