#1969 - Adding support for specifying sender to PipeSupport

This commit is contained in:
Viktor Klang 2012-04-24 12:04:31 +02:00
parent 670bb396f9
commit dec644e8a8
3 changed files with 19 additions and 9 deletions

View file

@ -19,6 +19,20 @@ class Future2ActorSpec extends AkkaSpec with DefaultTimeout {
expectMsgAllOf(1 second, 42, 42)
}
"support convenient sending to multiple destinations with implicit sender" in {
implicit val someActor = system.actorOf(Props(ctx Actor.emptyBehavior))
Future(42) pipeTo testActor pipeTo testActor
expectMsgAllOf(1 second, 42, 42)
lastSender must be(someActor)
}
"support convenient sending with explicit sender" in {
val someActor = system.actorOf(Props(ctx Actor.emptyBehavior))
Future(42).to(testActor, someActor)
expectMsgAllOf(1 second, 42)
lastSender must be(someActor)
}
"support reply via sender" in {
val actor = system.actorOf(Props(new Actor {
def receive = {

View file

@ -125,11 +125,7 @@ class Deployer(val settings: ActorSystem.Settings, val dynamicAccess: DynamicAcc
val within = Duration(deployment.getMilliseconds("within"), TimeUnit.MILLISECONDS)
val resizer: Option[Resizer] = if (config.hasPath("resizer")) {
Some(DefaultResizer(deployment.getConfig("resizer")))
} else {
None
}
val resizer: Option[Resizer] = if (config.hasPath("resizer")) Some(DefaultResizer(deployment.getConfig("resizer"))) else None
val router: RouterConfig = deployment.getString("router") match {
case "from-code" NoRouter

View file

@ -9,14 +9,14 @@ import akka.actor.{ Status, ActorRef }
trait PipeToSupport {
final class PipeableFuture[T](val future: Future[T]) {
def pipeTo(recipient: ActorRef): Future[T] =
def pipeTo(recipient: ActorRef)(implicit sender: ActorRef = null): Future[T] =
future onComplete {
case Right(r) recipient ! r
case Left(f) recipient ! Status.Failure(f)
}
def to(recipient: ActorRef): PipeableFuture[T] = {
pipeTo(recipient)
def to(recipient: ActorRef): PipeableFuture[T] = to(recipient, null)
def to(recipient: ActorRef, sender: ActorRef): PipeableFuture[T] = {
pipeTo(recipient)(sender)
this
}
}