polish “ask” pattern, see #1581

- move package objects into their respective package.scala file in the
  right directories
- make implicit conversion as well as explicit facility available under
  the same name akka.patterns.ask for easy import
- revert the logic to produce the Promise for the PromiseActorRef within
  the ActorRefProvider; supporting wrapping of external Promises does
  not seem to justify doing needless extra allocations in case of
  failure
- add scaladocs
- factor out “def provider” into trait ActorRefWithProvider, as it
  didn’t feel right attaching this information “by exception” to
  MinimalActorRef
This commit is contained in:
Roland 2012-01-17 17:04:20 +01:00
parent ce1d2f4721
commit 9c762dec20
11 changed files with 268 additions and 176 deletions

View file

@ -8,7 +8,6 @@ import akka.actor.Actor
import akka.actor.Props
import akka.event.Logging
import akka.dispatch.Future
import akka.Patterns
//#imports1
@ -221,6 +220,8 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
"using ask" in {
//#using-ask
import akka.patterns.ask
class MyActor extends Actor {
def receive = {
case x: String sender ! x.toUpperCase
@ -230,10 +231,10 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
val myActor = system.actorOf(Props(new MyActor), name = "myactor")
implicit val timeout = system.settings.ActorTimeout
val future = Patterns.ask(myActor, "hello")
val future = ask(myActor, "hello")
for (x future) println(x) //Prints "hello"
val result: Future[Int] = for (x Patterns.ask(myActor, 3).mapTo[Int]) yield { 2 * x }
val result: Future[Int] = for (x ask(myActor, 3).mapTo[Int]) yield { 2 * x }
//#using-ask
system.stop(myActor)