Class/Object

zio

Promise

Related Docs: object Promise | package zio

Permalink

final class Promise[E, A] extends Serializable

A promise represents an asynchronous variable, of zio.IO type, that can be set exactly once, with the ability for an arbitrary number of fibers to suspend (by calling await) and automatically resume when the variable is set.

Promises can be used for building primitive actions whose completions require the coordinated action of multiple fibers, and for building higher-level concurrent or asynchronous structures.

for {
  promise <- Promise.make[Nothing, Int]
  _       <- promise.succeed(42).delay(1.second).fork
  value   <- promise.await // Resumes when forked fiber completes promise
} yield value
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Promise
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

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. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def await(implicit trace: ZTraceElement): IO[E, A]

    Permalink

    Retrieves the value of the promise, suspending the fiber running the action until the result is available.

  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. def complete(io: IO[E, A])(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Completes the promise with the result of the specified effect.

    Completes the promise with the result of the specified effect. If the promise has already been completed, the method will produce false.

    Note that Promise.completeWith will be much faster, so consider using that if you do not need to memoize the result of the specified effect.

  8. def completeWith(io: IO[E, A])(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Completes the promise with the specified effect.

    Completes the promise with the specified effect. If the promise has already been completed, the method will produce false.

    Note that since the promise is completed with an effect, the effect will be evaluated each time the value of the promise is retrieved through combinators such as await, potentially producing different results if the effect produces different results on subsequent evaluations. In this case te meaning of the "exactly once" guarantee of Promise is that the promise can be completed with exactly one effect. For a version that completes the promise with the result of an effect see Promise.complete.

  9. def die(e: Throwable)(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Kills the promise with the specified error, which will be propagated to all fibers waiting on the value of the promise.

  10. def done(e: Exit[E, A])(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Exits the promise with the specified exit, which will be propagated to all fibers waiting on the value of the promise.

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  13. def fail(e: E)(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Fails the promise with the specified error, which will be propagated to all fibers waiting on the value of the promise.

  14. def failCause(e: Cause[E])(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Fails the promise with the specified cause, which will be propagated to all fibers waiting on the value of the promise.

  15. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. final def getClass(): Class[_]

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

    Permalink
    Definition Classes
    AnyRef → Any
  18. def interrupt(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Completes the promise with interruption.

    Completes the promise with interruption. This will interrupt all fibers waiting on the value of the promise as by the fiber calling this method.

  19. def interruptAs(fiberId: FiberId)(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Completes the promise with interruption.

    Completes the promise with interruption. This will interrupt all fibers waiting on the value of the promise as by the specified fiber.

  20. def isDone(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Checks for completion of this Promise.

    Checks for completion of this Promise. Produces true if this promise has already been completed with a value or an error and false otherwise.

  21. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  22. final def ne(arg0: AnyRef): Boolean

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

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

    Permalink
    Definition Classes
    AnyRef
  25. def poll(implicit trace: ZTraceElement): UIO[Option[IO[E, A]]]

    Permalink

    Checks for completion of this Promise.

    Checks for completion of this Promise. Returns the result effect if this promise has already been completed or a None otherwise.

  26. def succeed(a: A)(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Completes the promise with the specified value.

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

    Permalink
    Definition Classes
    AnyRef
  28. def toString(): String

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

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def halt(e: Cause[E])(implicit trace: ZTraceElement): UIO[Boolean]

    Permalink

    Halts the promise with the specified cause, which will be propagated to all fibers waiting on the value of the promise.

    Halts the promise with the specified cause, which will be propagated to all fibers waiting on the value of the promise.

    Annotations
    @deprecated
    Deprecated

    (Since version 2.0.0) use failCause

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped