Class

com.twitter.util

ConstFuture

Related Doc: package util

Permalink

class ConstFuture[A] extends Future[A]

A Future that is already completed. These are cheap in construction compared to Promises.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. ConstFuture
  2. Future
  3. Awaitable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ConstFuture(result: Try[A])

    Permalink

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. def addEventListener(listener: FutureEventListener[_ >: A]): Future[A]

    Permalink

    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.

    Definition Classes
    Future
  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def before[B](f: ⇒ Future[B])(implicit ev: <:<[ConstFuture.this.type, Future[Unit]]): Future[B]

    Permalink

    Sequentially compose this with f.

    Sequentially compose this with f. This is as flatMap, but discards the result of this. Note that this applies only Unit-valued Futures — i.e. side-effects.

    Definition Classes
    Future
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def delayed(howlong: Duration)(implicit timer: Timer): Future[A]

    Permalink

    Delay the completion of this Future for at least howlong from now.

    Delay the completion of this Future for at least howlong from now.

    Definition Classes
    Future
  9. def ensure(f: ⇒ Unit): Future[A]

    Permalink

    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.

    The returned Future will be satisfied when this, the original future, is done.

    f

    the side-effect to apply when the computation completes.

    Definition Classes
    Future
    Note

    this should be used for side-effects.

    See also

    respond if you need the result of the computation for usage in the side-effect.

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

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

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

    Permalink
    Definition Classes
    Future
  13. def finalize(): Unit

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

    Permalink

    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 and preserving the failed computation of this.

    Definition Classes
    Future
    See also

    map

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

    Permalink

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

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

    Definition Classes
    Future
  16. def foreach(k: (A) ⇒ Unit): Future[A]

    Permalink

    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.

    Definition Classes
    Future
    See also

    onSuccess

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

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

    Permalink

    If this, the original future, results in an exceptional computation, rescueException may convert the failure into a new result.

    If this, the original future, results in an exceptional computation, rescueException may convert the failure into a new result.

    The returned result is a Future that is satisfied when the original future and the callback, rescueException, are done.

    This is the equivalent of map for failed computations.

    Definition Classes
    Future
    See also

    rescue

  19. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  20. def interruptible(): Future[A]

    Permalink

    Makes a derivative Future which will be satisfied with the result of the parent.

    Makes a derivative Future which will be satisfied with the result of the parent. However, if it's interrupted, it will detach from the parent Future, satisfy itself with the exception raised to it, and won't propagate the interruption back to the parent Future.

    This is useful for when a Future is shared between many contexts, where it may not be useful to discard the underlying computation if just one context is no longer interested in the result. In particular, this is different from Future#masked in that it will prevent memory leaks if the parent Future will never be satisfied, because closures that are attached to this derivative Future will not be held onto by the killer Future.

    Definition Classes
    Future
  21. def isDefined: Boolean

    Permalink

    Is the result of the Future available yet?

    Is the result of the Future available yet?

    Definition Classes
    ConstFutureFuture
  22. def isDone(implicit ev: <:<[ConstFuture.this.type, Future[Unit]]): Boolean

    Permalink

    Checks whether a Unit-typed Future is done.

    Checks whether a Unit-typed Future is done. By convention, futures of type Future[Unit] are used for signalling.

    Definition Classes
    ConstFutureFuture
  23. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  24. def isReady(implicit permit: CanAwait): Boolean

    Permalink

    Is this Awaitable ready? In other words: would calling Awaitable.ready block?

    Is this Awaitable ready? In other words: would calling Awaitable.ready block?

    Definition Classes
    ConstFutureAwaitable
  25. def join[B](other: Future[B]): Future[(A, B)]

    Permalink

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

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

    Definition Classes
    Future
  26. def liftToTry: Future[Try[A]]

    Permalink

    Returns the result of the computation as a Future[Try[A]].

    Returns the result of the computation as a Future[Try[A]].

    Definition Classes
    Future
  27. def lowerFromTry[T](implicit ev: <:<[A, Try[T]]): Future[T]

    Permalink

    Lowers a Future[Try[T]] into a Future[T].

    Lowers a Future[Try[T]] into a Future[T].

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

    Permalink

    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 and preserving the failed computation of this.

    Definition Classes
    Future
    See also

    onSuccess for side-effecting chained computations.

    flatMap for computations that return Futures.

  29. def mask(pred: PartialFunction[Throwable, Boolean]): Future[A]

    Permalink

    Returns an identical future except that it ignores interrupts which match a predicate

    Returns an identical future except that it ignores interrupts which match a predicate

    Definition Classes
    Future
  30. def masked: Future[A]

    Permalink

    Returns an identical future that ignores all interrupts

    Returns an identical future that ignores all interrupts

    Definition Classes
    Future
  31. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  32. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  33. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  34. def onFailure(fn: (Throwable) ⇒ Unit): Future[A]

    Permalink

    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

    Definition Classes
    Future
    Note

    if fn is a PartialFunction and the input is not defined for a given Throwable, the resulting MatchError will propogate to the current Monitor. This will happen if you use a construct such as future.onFailure { case NonFatal(e) => ... } when the Throwable is "fatal".

    ,

    this should be used for side-effects.

    See also

    handle and rescue to produce a new Future from the result of the computation.

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

    Permalink

    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

    Definition Classes
    Future
    Note

    this should be used for side-effects.

    See also

    flatMap and map to produce a new Future from the result of the computation.

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

    Permalink

    A synonym for select: Choose the first Future to be satisfied.

    A synonym for select: Choose the first Future to be satisfied.

    Definition Classes
    Future
  37. def poll: Option[Try[A]]

    Permalink

    Polls for an available result.

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

    Definition Classes
    ConstFutureFuture
  38. def proxyTo[B >: A](other: Promise[B]): Unit

    Permalink

    Send updates from this Future to the other.

    Send updates from this Future to the other. other must not yet be satisfied at the time of the call. After this call, nobody else should satisfy other.

    Note: using proxyTo will mask interrupts to this future, and it's the user's responsibility to set an interrupt handler on other to raise on f. In some cases, using com.twitter.util.Promise.become may be more appropriate.

    Definition Classes
    Future
    See also

    com.twitter.util.Promise.become

  39. def raise(interrupt: Throwable): Unit

    Permalink

    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 involved 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).

    Definition Classes
    ConstFutureFuture
  40. def raiseWithin(timer: Timer, timeout: Duration, exc: Throwable): Future[A]

    Permalink

    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.

    Note: On timeout, the underlying future is interrupted.

    Definition Classes
    Future
  41. def raiseWithin(timeout: Duration, exc: Throwable)(implicit timer: Timer): Future[A]

    Permalink

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

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

    Note: On timeout, the underlying future is interrupted.

    Definition Classes
    Future
  42. def raiseWithin(timeout: Duration)(implicit timer: Timer): Future[A]

    Permalink

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

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

    Note: On timeout, the underlying future is interrupted.

    Definition Classes
    Future
  43. def ready(timeout: Duration)(implicit permit: CanAwait): ConstFuture.this.type

    Permalink

    Support for Await.ready.

    Support for Await.ready. The use of the implicit permit is an access control mechanism: only Await.ready may call this method.

    Definition Classes
    ConstFutureAwaitable
    Annotations
    @throws( classOf[TimeoutException] ) @throws( classOf[InterruptedException] )
  44. def rescue[B >: A](rescueException: PartialFunction[Throwable, Future[B]]): Future[B]

    Permalink

    If this, the original future, results in an exceptional computation, rescueException may convert the failure into a new result.

    If this, the original future, results in an exceptional computation, rescueException may convert the failure into a new result.

    The returned result is a Future that is satisfied when the original future and the callback, rescueException, are done.

    This is the equivalent of flatMap for failed computations.

    Definition Classes
    Future
    See also

    handle

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

    Permalink

    When the computation completes, invoke the given callback function.

    When the computation completes, invoke the given callback function.

    The returned Future will be satisfied when this, the original future, is done.

    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.).

    k

    the side-effect to apply when the computation completes. The value of the input to k will be the result of the computation to this future.

    returns

    a chained Future[A]

    Definition Classes
    ConstFutureFuture
    Note

    this should be used for side-effects.

    See also

    ensure if you are not interested in the result of the computation.

    transform to produce a new Future from the result of the computation.

  46. def result(timeout: Duration)(implicit permit: CanAwait): A

    Permalink

    Support for Await.result.

    Support for Await.result. The use of the implicit permit is an access control mechanism: only Await.result may call this method.

    Definition Classes
    ConstFutureAwaitable
    Annotations
    @throws( classOf[Exception] )
  47. def select[U >: A](other: Future[U]): Future[U]

    Permalink

    Choose the first Future to be satisfied.

    Choose the first Future to be satisfied.

    other

    another Future

    returns

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

    Definition Classes
    Future
  48. final def synchronized[T0](arg0: ⇒ T0): T0

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

    Permalink

    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)

    Definition Classes
    Future
  50. def toOffer: Offer[Try[A]]

    Permalink

    An offer for this future.

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

    Definition Classes
    Future
  51. def toString(): String

    Permalink
    Definition Classes
    ConstFuture → AnyRef → Any
  52. def transform[B](f: (Try[A]) ⇒ Future[B]): Future[B]

    Permalink

    When this future completes, run f on that completed result whether or not this computation was successful.

    When this future completes, run f on that completed result whether or not this computation was successful.

    The returned Future will be satisfied when this, the original future, and f are done.

    Definition Classes
    ConstFutureFuture
    See also

    handle and rescue for dealing strictly with exceptional computations.

    map and flatMap for dealing strictly with successful computations.

    respond for purely side-effecting callbacks.

  53. def transformedBy[B](transformer: FutureTransformer[A, B]): Future[B]

    Permalink

    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.

    Definition Classes
    Future
  54. def unit: Future[Unit]

    Permalink

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

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

    Definition Classes
    Future
  55. def voided: Future[Void]

    Permalink

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

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

    Definition Classes
    Future
  56. final def wait(): Unit

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

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

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

    Permalink

    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).

    Definition Classes
    Future
  60. def withFilter(p: (A) ⇒ Boolean): Future[A]

    Permalink
    Definition Classes
    Future
  61. def within(timer: Timer, timeout: Duration, exc: ⇒ Throwable): Future[A]

    Permalink

    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.

    Note: On timeout, the underlying future is not interrupted.

    timer

    to run timeout on.

    timeout

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

    exc

    exception to throw.

    Definition Classes
    Future
  62. def within(timer: Timer, timeout: Duration): Future[A]

    Permalink

    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.

    Note: On timeout, the underlying future is not interrupted.

    Definition Classes
    Future
  63. def within(timeout: Duration)(implicit timer: Timer): Future[A]

    Permalink

    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.

    Note: On timeout, the underlying future is not interrupted.

    Definition Classes
    Future

Deprecated Value Members

  1. def apply(timeout: Duration): A

    Permalink

    Block, but only as long as the given timeout, for the result of the Future to be available.

    Block, but only as long as the given timeout, for the result of the Future to be available.

    Definition Classes
    Future
    Annotations
    @deprecated
    Deprecated

    (Since version 6.2.x) Use Await.result

  2. def apply(): A

    Permalink

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

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

    Definition Classes
    Future
    Annotations
    @deprecated
    Deprecated

    (Since version 6.2.x) Use Await.result

  3. def cancel(): Unit

    Permalink
    Definition Classes
    Future
    Annotations
    @deprecated
    Deprecated

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

  4. final def get(timeout: Duration): Try[A]

    Permalink

    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.

    Definition Classes
    Future
    Annotations
    @deprecated
    Deprecated

    (Since version 6.2.x) Use Await.result(future.liftToTry)

  5. def get(): A

    Permalink

    Alias for apply().

    Alias for apply().

    Definition Classes
    Future
    Annotations
    @deprecated
    Deprecated

    (Since version 6.2.x) Use Await.result

  6. def isReturn: Boolean

    Permalink
    Definition Classes
    Future
    Annotations
    @deprecated
    Deprecated

    (Since version 6.2.x) Use Await.result(future.liftToTry).isReturn

  7. def isThrow: Boolean

    Permalink
    Definition Classes
    Future
    Annotations
    @deprecated
    Deprecated

    (Since version 6.2.x) Use Await.result(future.liftToTry).isThrow

Inherited from Future[A]

Inherited from Awaitable[A]

Inherited from AnyRef

Inherited from Any

Ungrouped