value ? is not a member of akka.actor.ActorRef

5,662 views
Skip to first unread message

Vinicius Carvalho

unread,
May 9, 2012, 10:58:16 PM5/9/12
to play-framework
Hi, just trying to get actors and play but not getting this error:

package actors

import akka.actor.Actor
import scala.util.Random
import akka.util.Timeout
import akka.util.duration._

class NodeBalancer extends Actor{


def receive = {
case nodeId : Int =>
val r = new Random
val wait = r.nextInt(80) + 20
Thread.sleep(wait)
sender ! ("Node id " + nodeId + " took " + wait + " ms to be
processed")
case _ => println("WTF")
}

}

object NodeBalancer {
implicit val timeout = Timeout(1 second)
}

def index = Action {
val actor = Akka.system.actorOf(Props[NodeBalancer], name ="node
balancer")

Async {
(actor ? 17).mapTo[String].asPromise.map {
response => Ok(response)
}
}
}
I get an error, as ActorRef does not contain the ? method. Really
confused here, thought that ? (ask) was the way to get a future from
an actor.

Regards

Nilanjan

unread,
May 10, 2012, 12:03:55 AM5/10/12
to play-framework
You have to import akka.pattern.ask to use '?'. There is a implicit
conversion from ActorRef to AskableActorRef.

Thanks
Nilanjan

On May 9, 8:58 pm, Vinicius Carvalho <viniciusccarva...@gmail.com>
wrote:

Depanker Sharma

unread,
Aug 23, 2015, 9:55:16 AM8/23/15
to play-framework
Thanks, worked for me
Reply all
Reply to author
Forward
0 new messages