Packages

final class Promise[E, A] extends AnyVal with 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. AnyVal
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): Int
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. final def await: IO[E, A]

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

  6. final def complete(io: IO[E, A]): UIO[Boolean]

    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.

  7. final def completeWith(io: IO[E, A]): UIO[Boolean]

    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.

  8. final def die(e: Throwable): UIO[Boolean]

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

  9. final def done(e: Exit[E, A]): UIO[Boolean]

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

  10. final def fail(e: E): UIO[Boolean]

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

  11. def getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  12. final def halt(e: Cause[E]): UIO[Boolean]

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

  13. final def interrupt: UIO[Boolean]

    Completes the promise with interruption.

    Completes the promise with interruption. This will interrupt all fibers waiting on the value of the promise.

  14. final def isDone: UIO[Boolean]

    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.

  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. final def poll: UIO[Option[IO[E, A]]]

    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.

  17. final def succeed(a: A): UIO[Boolean]

    Completes the promise with the specified value.

  18. def toString(): String
    Definition Classes
    Any

Deprecated Value Members

  1. final def done(io: IO[E, A]): UIO[Boolean]

    Alias for Promise.complete

    Alias for Promise.complete

    Annotations
    @deprecated
    Deprecated

    (Since version 1.0.0) use Promise.complete

Inherited from Serializable

Inherited from Serializable

Inherited from AnyVal

Inherited from Any

Ungrouped