Closed wanghc78 closed 8 years ago
The current fix #d931cfb partially solve the problem. Now user can create child actor in preStart()
But the child actors fields can only be optional var, like
class A : Actor {
var b:B!
init() {...}
preStart() { b = actorOf(B.init, "B") }
}
If we want to support let b:B!
, the field assign must still be inside init(), then we still have to pass actorSystem/ref into init(), which causes we can not write arbitrary constructors of an actor.
The code will throw the NPE
The reason is at the current actor A init phase, the actor's
ref
is not assigned. So it cannot call actorOf() which will use theref
field, to create actor B.