com.twitter.util

Future

abstract class Future[+A] extends AnyRef

A computation evaluated asynchronously. This implementation of Future does not assume any concrete implementation; in particular, it does not couple the user to a specific executor or event loop.

Note that this class extends Try[_] indicating that the results of the computation may succeed or fail.

Futures are also com.twitter.util.Cancellable, but with special semantics: the cancellation signal is only guaranteed to be delivered when the promise has not yet completed.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Future
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Future()

Abstract Value Members

  1. abstract def get(timeout: Duration): Try[A]

    Demands that the result of the future be available within timeout.

    Demands that the result of the future be available within timeout. The result is a Return[_] or Throw[_] depending upon whether the computation finished in time.

  2. abstract def poll: Option[Try[A]]

    Polls for an available result.

    Polls for an available result. If the Future has been satisfied, returns Some(result), otherwise None.

  3. abstract def raise(interrupt: Throwable): Unit

    Raise the given throwable as an interrupt.

    Raise the given throwable as an interrupt. Interrupts are one-shot and latest-interrupt wins. That is, the last interrupt to have been raised is delivered exactly once to the Promise responsible for making progress on the future (multiple such promises may be involed in flatMap chains).

    Raising an interrupt does not alter the externally observable state of the Future. They are used to signal to the producer of the future's value that the result is no longer desired (for whatever reason given in the passed Throwable).

  4. abstract def respond(k: (Try[A]) ⇒ Unit): Future[A]

    When the computation completes, invoke the given callback function.

    When the computation completes, invoke the given callback function. Respond() yields a Try (either a Return or a Throw). This method is most useful for very generic code (like libraries). Otherwise, it is a best practice to use one of the alternatives (onSuccess(), onFailure(), etc.). Note that almost all methods on Future[_] are written in terms of respond(), so this is the essential template method for use in concrete subclasses.

    returns

    a chained Future[A]

  5. abstract def transform[B](f: (Try[A]) ⇒ Future[B]): Future[B]

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 addEventListener(listener: FutureEventListener[_ >: A]): Future[A]

    Register a FutureEventListener to be invoked when the computation completes.

    Register a FutureEventListener to be invoked when the computation completes. This method is typically used by Java programs because it avoids the use of small Function objects.

    Compare this method to transformedBy. The difference is that addEventListener is used to perform a simple action when a computation completes, such as recording data in a log-file. It analogous to a void method in Java: it has side-effects and no return value. transformedBy, on the other hand, is used to transform values from one type to another, or to chain a series of asynchronous calls and return the result. It is analogous to methods in Java that have a return-type. Note that transformedBy and addEventListener are not mutually exclusive and may be profitably combined.

  7. def apply(timeout: Duration): A

    Block, but only as long as the given Timeout.

  8. def apply(): A

    Block indefinitely, wait for the result of the Future to be available.

  9. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  10. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  11. def ensure(f: ⇒ Unit): Future[A]

    Invoked regardless of whether the computation completed successfully or unsuccessfully.

    Invoked regardless of whether the computation completed successfully or unsuccessfully. Implemented in terms of respond so that subclasses control evaluation order. Returns a chained Future.

  12. final def eq(arg0: AnyRef): Boolean

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

    Definition Classes
    AnyRef → Any
  14. def filter(p: (A) ⇒ Boolean): Future[A]

  15. def finalize(): Unit

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

    If this, the original future, succeeds, run f on the result.

    If this, the original future, succeeds, run f on the result.

    The returned result is a Future that is satisfied when the original future and the callback, f, are done. If the original future fails, this one will also fail, without executing f.

    See also

    map()

  17. def flatten[B](implicit ev: <:<[A, Future[B]]): Future[B]

    Converts a Future[Future[B]] into a Future[B]

  18. def foreach(k: (A) ⇒ Unit): Future[A]

    Invoke the callback only if the Future returns successfully.

    Invoke the callback only if the Future returns successfully. Useful for Scala for comprehensions. Use onSuccess instead of this method for more readable code.

  19. def get(): A

    Alias for apply().

  20. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  21. def handle[B >: A](rescueException: PartialFunction[Throwable, B]): Future[B]

  22. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  23. def isDefined: Boolean

    Is the result of the Future available yet?

  24. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  25. def isReturn: Boolean

  26. def isThrow: Boolean

  27. def join[B](other: Future[B]): Future[(A, B)]

    Combines two Futures into one Future of the Tuple of the two results.

  28. def map[B](f: (A) ⇒ B): Future[B]

    If this, the original future, succeeds, run f on the result.

    If this, the original future, succeeds, run f on the result.

    The returned result is a Future that is satisfied when the original future and the callback, f, are done. If the original future fails, this one will also fail, without executing f.

    See also

    flatMap()

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

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

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

    Definition Classes
    AnyRef
  32. def onFailure(rescueException: (Throwable) ⇒ Unit): Future[A]

    Invoke the function on the error, if the computation was unsuccessful.

    Invoke the function on the error, if the computation was unsuccessful. Returns a chained Future as in respond.

    returns

    chained Future

  33. def onSuccess(f: (A) ⇒ Unit): Future[A]

    Invoke the function on the result, if the computation was successful.

    Invoke the function on the result, if the computation was successful. Returns a chained Future as in respond.

    returns

    chained Future

  34. def or[U >: A](other: Future[U]): Future[U]

    A synonym for select(): Choose the first Future to succeed.

  35. def proxyTo[B >: A](other: Promise[B]): Unit

    Send updates from this Future to the other.

    Send updates from this Future to the other. other must not yet be satisfied.

  36. def rescue[B >: A](rescueException: PartialFunction[Throwable, Future[B]]): Future[B]

  37. def select[U >: A](other: Future[U]): Future[U]

    Choose the first Future to succeed.

    Choose the first Future to succeed.

    other

    another Future

    returns

    a new Future whose result is that of the first of this and other to return

  38. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  39. def toJavaFuture: java.util.concurrent.Future[_ <: A]

    Convert a Twitter Future to a Java native Future.

    Convert a Twitter Future to a Java native Future. This should match the semantics of a Java Future as closely as possible to avoid issues with the way another API might use them. See:

    http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html#cancel(boolean)

  40. def toOffer: Offer[Try[A]]

    An offer for this future.

    An offer for this future. The offer is activated when the future is satisfied.

  41. def toString(): String

    Definition Classes
    AnyRef → Any
  42. def transformedBy[B](transformer: FutureTransformer[A, B]): Future[B]

    Transform the Future[A] into a Future[B] using the FutureTransformer.

    Transform the Future[A] into a Future[B] using the FutureTransformer. The FutureTransformer handles both success (Return) and failure (Throw) values by implementing map/flatMap and handle/rescue. This method is typically used by Java programs because it avoids the use of small Function objects.

    Compare this method to addEventListener. The difference is that addEventListener is used to perform a simple action when a computation completes, such as recording data in a log-file. It analogous to a void method in Java: it has side-effects and no return value. transformedBy, on the other hand, is used to transform values from one type to another, or to chain a series of asynchronous calls and return the result. It is analogous to methods in Java that have a return-type. Note that transformedBy and addEventListener are not mutually exclusive and may be profitably combined.

    Note: The FutureTransformer must implement either flatMap or map and may optionally implement handle. Failing to implement a method will result in a run-time (AbstractMethod) error.

  43. def unit: Future[Unit]

    Convert this Future[A] to a Future[Unit] by discarding the result.

  44. def voided: Future[Void]

    Convert this Future[A] to a Future[Void] by discarding the result.

  45. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws()
  48. def willEqual[B](that: Future[B]): Promise[Boolean]

    Returns a Future[Boolean] indicating whether two Futures are equivalent.

    Returns a Future[Boolean] indicating whether two Futures are equivalent. Note that Future.exception(e).willEqual(Future.exception(e)) == Future.value(true).

  49. def within(timer: Timer, timeout: Duration): Future[A]

    Returns a new Future that will error if this Future does not return in time.

    Returns a new Future that will error if this Future does not return in time.

    timeout

    indicates how long you are willing to wait for the result to be available.

  50. def within(timeout: Duration)(implicit timer: Timer): Future[A]

    Same as the other within, but with an implicit timer.

    Same as the other within, but with an implicit timer. Sometimes this is more convenient.

Deprecated Value Members

  1. def cancel(): Unit

    Annotations
    @deprecated
    Deprecated

    (Since version 6.0.0) Provided for API compatibility; use raise() instead.

  2. def void: Future[Void]

    Annotations
    @deprecated
    Deprecated

    (Since version 5.x) 'void' is a reserved word in javac.

Inherited from AnyRef

Inherited from Any

Ungrouped