final class Promise[E, A] extends Serializable
A promise represents an asynchronous variable, of zio.ZIO 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
- Alphabetic
- By Inheritance
- Promise
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def await(implicit trace: Trace): IO[E, A]
Retrieves the value of the promise, suspending the fiber running the action until the result is available.
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def complete(io: IO[E, A])(implicit trace: Trace): 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.
- def completeWith(io: IO[E, A])(implicit trace: Trace): 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 ofPromise
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. - def die(e: Throwable)(implicit trace: Trace): UIO[Boolean]
Kills the promise with the specified error, which will be propagated to all fibers waiting on the value of the promise.
- def done(e: Exit[E, A])(implicit trace: Trace): UIO[Boolean]
Exits the promise with the specified exit, which will be propagated to all fibers waiting on the value of the promise.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def fail(e: E)(implicit trace: Trace): UIO[Boolean]
Fails the promise with the specified error, which will be propagated to all fibers waiting on the value of the promise.
- def failCause(e: Cause[E])(implicit trace: Trace): UIO[Boolean]
Fails the promise with the specified cause, which will be propagated to all fibers waiting on the value of the promise.
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def interrupt(implicit trace: Trace): UIO[Boolean]
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.
- def interruptAs(fiberId: FiberId)(implicit trace: Trace): UIO[Boolean]
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.
- def isDone(implicit trace: Trace): 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.
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def poll(implicit trace: Trace): 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. - def refailCause(e: Cause[E])(implicit trace: Trace): UIO[Boolean]
Fails the promise with the specified cause, which will be propagated to all fibers waiting on the value of the promise.
Fails the promise with the specified cause, which will be propagated to all fibers waiting on the value of the promise. No new stack trace is attached to the cause.
- def succeed(a: A)(implicit trace: Trace): UIO[Boolean]
Completes the promise with the specified value.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()