@@ -9,28 +9,37 @@ class Core
99 attr_reader :reference , :name , :path , :logger , :parent_core
1010 private :parent_core
1111
12- # @param [Reference, nil] parent of an actor spawning this one
13- # @param [String] name
14- # @param [Context] actress_class a class to be instantiated defining Actor's behaviour
15- # @param args arguments for actress_class instantiation
16- # @param block for actress_class instantiation
17- def initialize ( parent , name , actress_class , *args , &block )
18- @mailbox = Array . new
19- @one_by_one = OneByOne . new
20- @executor = Concurrent . configuration . global_task_pool # TODO make configurable
21- @parent_core = ( Type! parent , Reference , NilClass ) && parent . send ( :core )
22- @name = ( Type! name , String , Symbol ) . to_s
23- @children = [ ]
12+ # @option opts [String] name
13+ # @option opts [Reference, nil] parent of an actor spawning this one
14+ # @option opts [Context] actress_class a class to be instantiated defining Actor's behaviour
15+ # @option opts [Array<Object>] args arguments for actress_class instantiation
16+ # @option opts [Executor] executor, default is `Concurrent.configuration.global_task_pool`
17+ # @param [Proc] block for class instantiation
18+ def initialize ( opts = { } , &block )
19+ @mailbox = Array . new
20+ @one_by_one = OneByOne . new
21+ # noinspection RubyArgCount
22+ @terminated = Event . new
23+ @executor = Type! opts . fetch ( :executor , Concurrent . configuration . global_task_pool ) , Executor
24+ @children = [ ]
25+ @reference = Reference . new self
26+ @name = ( Type! opts . fetch ( :name ) , String , Symbol ) . to_s
27+
28+ parent = opts [ :parent ]
29+ @parent_core = ( Type! parent , Reference , NilClass ) && parent . send ( :core )
30+ if @parent_core . nil? && @name != '/'
31+ raise 'only root has no parent'
32+ end
33+
2434 @path = @parent_core ? File . join ( @parent_core . path , @name ) : @name
2535 @logger = Logger . new ( $stderr) # TODO add proper logging
2636 @logger . progname = @path
27- @reference = Reference . new self
28- # noinspection RubyArgCount
29- @terminated = Event . new
3037
31- parent_core . add_child reference if parent_core
38+ @parent_core . add_child reference if @parent_core
39+
40+ @actress_class = actress_class = Child! opts . fetch ( :class ) , Context
41+ args = opts . fetch ( :args , [ ] )
3242
33- @actress_class = Child! actress_class , Context
3443 schedule_execution do
3544 begin
3645 @actress = actress_class . new *args , &block
@@ -42,9 +51,9 @@ def initialize(parent, name, actress_class, *args, &block)
4251 end
4352 end
4453
45- # @return [Reference] of parent actor
54+ # @return [Reference, nil ] of parent actor
4655 def parent
47- @parent_core . reference
56+ @parent_core && @parent_core . reference
4857 end
4958
5059 # @return [Array<Reference>] of children actors
@@ -155,7 +164,7 @@ def schedule_execution
155164 Thread . current [ :__current_actress__ ] = reference
156165 yield
157166 rescue => e
158- logger . error e
167+ logger . fatal e
159168 ensure
160169 Thread . current [ :__current_actress__ ] = nil
161170 end
0 commit comments