akka.dispatch

Future

sealed trait Future[+T] extends Awaitable[T]

Trait representing a value that may not have been computed yet.

Linear Supertypes
Awaitable[T], AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. Future
  2. Awaitable
  3. AnyRef
  4. Any
Visibility
  1. Public
  2. All

Type Members

  1. final class FutureWithFilter[+A] extends AnyRef

Abstract Value Members

  1. implicit abstract def executor: ExecutionContext

    Attributes
    protected
  2. abstract def isCompleted: Boolean

    Tests whether this Future has been completed.

  3. abstract def onComplete[U](func: (Either[Throwable, T]) ⇒ U): Future.this.type

    When this Future is completed, apply the provided function to the Future.

    When this Future is completed, apply the provided function to the Future. If the Future has already been completed, this will apply immediately. Multiple callbacks may be registered; there is no guarantee that they will be executed in a particular order.

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  4. abstract def ready(atMost: Duration)(implicit permit: CanAwait): Future.this.type

    Should throw java.util.concurrent.TimeoutException if times out This method should not be called directly.

    Should throw java.util.concurrent.TimeoutException if times out This method should not be called directly.

    Definition Classes
    Awaitable
    Annotations
    @throws( classOf[TimeoutException] )
  5. abstract def result(atMost: Duration)(implicit permit: CanAwait): T

    Throws exceptions if cannot produce a T within the specified time This method should not be called directly.

    Throws exceptions if cannot produce a T within the specified time This method should not be called directly.

    Definition Classes
    Awaitable
    Annotations
    @throws( classOf[Exception] )
  6. abstract def value: Option[Either[Throwable, T]]

    The contained value of this Future.

    The contained value of this Future. Before this Future is completed the value will be None. After completion the value will be Some(Right(t)) if it contains a valid result, or Some(Left(error)) if it contains an exception.

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def andThen[U](pf: PartialFunction[Either[Throwable, T], U]): Future[T]

    Returns a new Future that will contain the completed result of this Future, and which will invoke the supplied PartialFunction when completed.

    Returns a new Future that will contain the completed result of this Future, and which will invoke the supplied PartialFunction when completed.

    This allows for establishing order of side-effects.

     Future { 5 } andThen {
       case something => assert(something is awesome)
     } andThen {
       case Left(t) => handleProblem(t)
       case Right(v) => dealWithSuccess(v)
     }
    

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  7. def apply(): T @util.continuations.package.cps[akka.dispatch.Future[Any]]

    For use only within a Future.

    For use only within a Future.flow block or another compatible Delimited Continuations reset block.

    Returns the result of this Future without blocking, by suspending execution and storing it as a continuation until the result is available.

  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  10. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  12. final def failed: Future[Throwable]

    Returns a failure projection of this Future If this becomes completed with a failure, that failure will be the success of the returned Future If this becomes completed with a result, then the returned future will fail with a NoSuchElementException

  13. def fallbackTo[U >: T](that: Future[U]): Future[U]

    Returns a new Future that will either hold the successful value of this Future, or, it this Future fails, it will hold the result of "that" Future.

  14. final def filter(pred: (T) ⇒ Boolean): Future[T]

    Returns a new Future that will hold the successful result of this Future if it matches the given predicate, if it doesn't match, the resulting Future will be a failed Future with a MatchError, of if this Future fails, that failure will be propagated to the returned Future

    Returns a new Future that will hold the successful result of this Future if it matches the given predicate, if it doesn't match, the resulting Future will be a failed Future with a MatchError, of if this Future fails, that failure will be propagated to the returned Future

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  15. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  16. final def flatMap[A](f: (T) ⇒ Future[A]): Future[A]

    Creates a new Future by applying a function to the successful result of this Future, and returns the result of the function as the new Future.

    Creates a new Future by applying a function to the successful result of this Future, and returns the result of the function as the new Future. If this Future is completed with an exception then the new Future will also contain this exception. Example:

    val future1 = for {
      a: Int    <- actor ? "Hello" // returns 5
      b: String <- actor ? a       // returns "10"
      c: String <- actor ? 7       // returns "14"
    } yield b + "-" + c
    

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  17. final def foreach[U](f: (T) ⇒ U): Unit

    Same as onSuccess { case r => f(r) } but is also used in for-comprehensions

    Same as onSuccess { case r => f(r) } but is also used in for-comprehensions

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  18. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  19. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  20. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  21. final def map[A](f: (T) ⇒ A): Future[A]

    Creates a new Future by applying a function to the successful result of this Future.

    Creates a new Future by applying a function to the successful result of this Future. If this Future is completed with an exception then the new Future will also contain this exception. Example:

    val future1 = for {
      a: Int    <- actor ? "Hello" // returns 5
      b: String <- actor ? a       // returns "10"
      c: String <- actor ? 7       // returns "14"
    } yield b + "-" + c
    

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  22. final def mapTo[A](implicit m: Manifest[A]): Future[A]

    Creates a new Future[A] which is completed with this Future's result if that conforms to A's erased type or a ClassCastException otherwise.

    Creates a new Future[A] which is completed with this Future's result if that conforms to A's erased type or a ClassCastException otherwise.

    When used from Java, to create the Manifest, use: import static akka.japi.Util.manifest; future.mapTo(manifest(MyClass.class));

  23. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  24. final def notify(): Unit

    Definition Classes
    AnyRef
  25. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  26. final def onFailure[U](pf: PartialFunction[Throwable, U]): Future.this.type

    When the future is completed with an exception, apply the provided PartialFunction to the exception.

    When the future is completed with an exception, apply the provided PartialFunction to the exception. See onComplete for more details.

      future onFailure {
        case NumberFormatException ⇒ target ! "wrong format"
      }
    

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  27. final def onSuccess[U](pf: PartialFunction[T, U]): Future.this.type

    When the future is completed with a valid result, apply the provided PartialFunction to the result.

    When the future is completed with a valid result, apply the provided PartialFunction to the result. See onComplete for more details.

      future onSuccess {
        case Foo ⇒ target ! "foo"
        case Bar ⇒ target ! "bar"
      }
    

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  28. final def recover[A >: T](pf: PartialFunction[Throwable, A]): Future[A]

    Creates a new Future that will handle any matching Throwable that this Future might contain.

    Creates a new Future that will handle any matching Throwable that this Future might contain. If there is no match, or if this Future contains a valid result then the new Future will contain the same. Example:

    Future(6 / 0) recover { case e: ArithmeticException ⇒ 0 } // result: 0
    Future(6 / 0) recover { case e: NotFoundException   ⇒ 0 } // result: exception
    Future(6 / 2) recover { case e: ArithmeticException ⇒ 0 } // result: 3
    

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  29. def recoverWith[U >: T](pf: PartialFunction[Throwable, Future[U]]): Future[U]

    Returns a new Future that will, in case this future fails, be completed with the resulting Future of the given PartialFunction, if the given PartialFunction matches the failure of the original Future.

    Returns a new Future that will, in case this future fails, be completed with the resulting Future of the given PartialFunction, if the given PartialFunction matches the failure of the original Future.

    If the PartialFunction throws, that Throwable will be propagated to the returned Future.

    Example:

     val f = Future { Int.MaxValue }
     Future (6 / 0) recoverWith { case e: ArithmeticException => f } // result: Int.MaxValue
    

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  30. final def resolve[X](source: Either[Throwable, X]): Either[Throwable, X]

    Attributes
    protected
  31. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  32. def toString(): String

    Definition Classes
    AnyRef → Any
  33. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  34. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  35. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  36. final def withFilter(p: (T) ⇒ Boolean): FutureWithFilter[T]

    Used by for-comprehensions

    Used by for-comprehensions

    Note: the callback function may (and probably will) run in another thread, and therefore should not refer to any unsynchronized state. In particular, if using this method from an actor, do not access the state of the actor from the callback function. Promise.completeWith, PipeableFuture.pipeTo, and Future.fallbackTo are some methods to consider using when possible, to avoid concurrent callbacks.

  37. def zip[U](that: Future[U]): Future[(T, U)]

    returns

    a new Future that will contain a tuple containing the successful result of this and that Future. If this or that fail, they will race to complete the returned Future with their failure. The returned Future will not be completed if neither this nor that are completed.

Inherited from Awaitable[T]

Inherited from AnyRef

Inherited from Any