Skip to content

Instantly share code, notes, and snippets.

@sc6l6d3v
Created October 19, 2016 21:42
Show Gist options
  • Save sc6l6d3v/dff7c46e7fa0bad83311833c8e9fb811 to your computer and use it in GitHub Desktop.
Save sc6l6d3v/dff7c46e7fa0bad83311833c8e9fb811 to your computer and use it in GitHub Desktop.
// works perfectly in amm
import $ivy.`com.typesafe.akka::akka-actor:2.4.11`,akka.actor._, scala.concurrent._, scala.concurrent.duration._
val system = ActorSystem("hoge")
class PrintActor(dummy: String) extends Actor{ def receive = { case msg => println(msg) } }
val a = system.actorOf(Props(classOf[PrintActor],"first"),"aaa")
val b = system.actorOf(Props(classOf[PrintActor],"second"),"bbb")
Await.result(system.actorSelection("/user/aaa").resolveOne(1.second), 1.second)
{
def findRef(path: String): Option[ActorRef] =
try {
Some(Await.result(system.actorSelection(s"/user/$path").resolveOne(1.second), 1.second))
} catch {
case ex: Throwable => None
}
}
findRef("aaa")
findRef("bbb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment