All Downloads are FREE. Search and download functionalities are using the official Maven repository.

akka.pattern.PipeToSupport.scala Maven / Gradle / Ivy

There is a newer version: 2.0.5-protobuf-2.5-java-1.5
Show newest version
/**
 * Copyright (C) 2009-2012 Typesafe Inc. 
 */
package akka.pattern

import akka.dispatch.Future
import akka.actor.{ Status, ActorRef }

trait PipeToSupport {

  final class PipeableFuture[T](val future: Future[T]) {
    def pipeTo(recipient: ActorRef): Future[T] =
      future onComplete {
        case Right(r) ⇒ recipient ! r
        case Left(f)  ⇒ recipient ! Status.Failure(f)
      }

    def to(recipient: ActorRef): PipeableFuture[T] = {
      pipeTo(recipient)
      this
    }
  }

  /**
   * Import this implicit conversion to gain the `pipeTo` method on [[akka.dispatch.Future]]:
   *
   * {{{
   * import akka.pattern.pipe
   *
   * Future { doExpensiveCalc() } pipeTo nextActor
   *
   * or
   *
   * pipe(someFuture) to nextActor
   *
   * }}}
   */
  implicit def pipe[T](future: Future[T]): PipeableFuture[T] = new PipeableFuture(future)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy