scalaz.concurrent

Future

sealed abstract class Future[+A] extends AnyRef

Future is a trampolined computation producing an A that may include asynchronous steps. Like Trampoline, arbitrary monadic expressions involving map and flatMap are guaranteed to use constant stack space. But in addition, one may construct a Future from an asynchronous computation, represented as a function, listen: (A => Unit) => Unit, which registers a callback that will be invoked when the result becomes available. This makes Future useful as a concurrency primitive and as a control structure for wrapping callback-based APIs with a more straightforward, monadic API.

Unlike the Future implementation in scala 2.10, map and flatMap do NOT spawn new tasks and do not require an implicit ExecutionContext. Instead, map and flatMap merely add to the current (trampolined) continuation that will be run by the 'current' thread, unless explicitly forked via Future.fork or Future.apply. This means that Future achieves much better thread reuse than the 2.10 implementation and avoids needless thread pool submit cycles.

Future also differs from the scala 2.10 Future type in that it does not necessarily represent a _running_ computation. Instead, we reintroduce nondeterminism _explicitly_ using the functions of the scalaz.Nondeterminism interface. This simplifies our implementation and makes code easier to reason about, since the order of effects and the points of nondeterminism are made fully explicit and do not depend on Scala's evaluation order.

IMPORTANT NOTE: Future does not include any error handling and should generally only be used as a building block by library writers who want to build on Future's capabilities but wish to design their own error handling strategy. See scalaz.concurrent.Task for a type that extends Future with proper error handling -- it is merely a wrapper for Future[Throwable \/ A] with a number of additional convenience functions.

Source
Future.scala
Linear Supertypes
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()

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 after(t: Long): Future[A]

  7. def after(t: Duration): Future[A]

    Returns a Future that delays the execution of this Future by the duration t.

  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. def clone(): AnyRef

    Attributes
    protected[java.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. def finalize(): Unit

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

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

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

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

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

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

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

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

    Definition Classes
    AnyRef
  21. final def step: Future[A]

    Evaluate this Future to a result, or another asynchronous computation.

    Evaluate this Future to a result, or another asynchronous computation. This has the effect of stripping off any 'pure' trampolined computation at the start of this Future.

    Annotations
    @tailrec()
  22. final def stepInterruptibly(cancel: AtomicBoolean): Future[A]

    Like step, but may be interrupted by setting cancel to true.

    Like step, but may be interrupted by setting cancel to true.

    Annotations
    @tailrec()
  23. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  24. def timed(timeout: Duration)(implicit scheduler: ScheduledExecutorService = Strategy.DefaultTimeoutScheduler): Future[\/[Throwable, A]]

  25. def timed(timeoutInMillis: Long)(implicit scheduler: ScheduledExecutorService): Future[\/[Throwable, A]]

    Returns a Future which returns a TimeoutException after timeoutInMillis, and attempts to cancel the running computation.

    Returns a Future which returns a TimeoutException after timeoutInMillis, and attempts to cancel the running computation. This implementation will not block the future's execution thread

  26. def toString(): String

    Definition Classes
    AnyRef → Any
  27. def unsafePerformAsync(cb: (A) ⇒ Unit): Unit

    Run this Future, passing the result to the given callback once available.

    Run this Future, passing the result to the given callback once available. Any pure, non-asynchronous computation at the head of this Future will be forced in the calling thread. At the first Async encountered, control switches to whatever thread backs the Async and this function returns.

  28. def unsafePerformAsyncInterruptibly(cb: (A) ⇒ Unit, cancel: AtomicBoolean): Unit

    Run this computation to obtain an A, so long as cancel remains false.

    Run this computation to obtain an A, so long as cancel remains false. Because of trampolining, we get frequent opportunities to cancel while stepping through the trampoline, this should provide a fairly robust means of cancellation.

  29. def unsafePerformListen(cb: (A) ⇒ Free.Trampoline[Unit]): Unit

    Run this computation to obtain an A, then invoke the given callback.

    Run this computation to obtain an A, then invoke the given callback. Also see unsafePerformAsync.

  30. def unsafePerformListenInterruptibly(cb: (A) ⇒ Free.Trampoline[Unit], cancel: AtomicBoolean): Unit

    Run this computation to obtain an A, so long as cancel remains false.

    Run this computation to obtain an A, so long as cancel remains false. Because of trampolining, we get frequent opportunities to cancel while stepping through the trampoline, so this should provide a fairly robust means of cancellation.

  31. def unsafePerformSync: A

    Run this Future and block awaiting its result.

  32. def unsafePerformSyncAttemptFor(timeout: Duration): \/[Throwable, A]

  33. def unsafePerformSyncAttemptFor(timeoutInMillis: Long): \/[Throwable, A]

    Like unsafePerformSyncFor, but returns TimeoutException as left value.

    Like unsafePerformSyncFor, but returns TimeoutException as left value. Will not report any other exceptions that may be raised during computation of A

  34. def unsafePerformSyncFor(timeout: Duration): A

  35. def unsafePerformSyncFor(timeoutInMillis: Long): A

    Run this Future and block until its result is available, or until timeoutInMillis milliseconds have elapsed, at which point a TimeoutException will be thrown and the Future will attempt to be canceled.

  36. def unsafeStart: Future[A]

    Begins running this Future and returns a new future that blocks waiting for the result.

    Begins running this Future and returns a new future that blocks waiting for the result. Note that this will start executing side effects immediately, and is thus morally equivalent to unsafePerformIO. The resulting Future cannot be rerun to repeat the effects.

    Use with care.

  37. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def attemptRunFor(timeout: Duration): \/[Throwable, A]

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use unsafePerformSyncAttemptFor

  2. def attemptRunFor(timeoutInMillis: Long): \/[Throwable, A]

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use unsafePerformSyncAttemptFor

  3. def listen(cb: (A) ⇒ Free.Trampoline[Unit]): Unit

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use unsafePerformListen

  4. def listenInterruptibly(cb: (A) ⇒ Free.Trampoline[Unit], cancel: AtomicBoolean): Unit

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use unsafePerformListenInterruptibly

  5. def run: A

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use unsafePerformSync

  6. def runAsync(cb: (A) ⇒ Unit): Unit

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use unsafePerformAsync

  7. def runAsyncInterruptibly(cb: (A) ⇒ Unit, cancel: AtomicBoolean): Unit

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use unsafePerformAsyncInterruptibly

  8. def runFor(timeout: Duration): A

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use unsafePerformSyncFor

  9. def runFor(timeoutInMillis: Long): A

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use unsafePerformSyncFor

  10. def start: Future[A]

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use unsafeStart

  11. def unsafePerformTimed(timeoutInMillis: Long)(implicit scheduler: ScheduledExecutorService): Future[\/[Throwable, A]]

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use timed

  12. def unsafePerformTimed(timeout: Duration)(implicit scheduler: ScheduledExecutorService = Strategy.DefaultTimeoutScheduler): Future[\/[Throwable, A]]

    Annotations
    @deprecated
    Deprecated

    (Since version 7.2) use timed

Inherited from AnyRef

Inherited from Any

Ungrouped