akka.net is there a a way to get or create actor

前端 未结 1 1858
悲哀的现实
悲哀的现实 2021-01-18 10:38

For my actor hierarchy, I do not know all the actors I need until I process the data through a few actors, so I\'m looking for a way to either return an existing ActorRef or

相关标签:
1条回答
  • 2021-01-18 11:06

    You can check if current actor has a child with provided name by using Context.Child(actorName) method. It will return actor ref of the target actor if it exists or ActorRefs.Nobody if there is no such actor.

    Code in your case could look like:

    var child = Context.Child(actorName);
    if (Equals(child, ActorRefs.Nobody))
        child = Context.ActorOf(MyActor.Props(message), actorName);
    
    0 讨论(0)
提交回复
热议问题