Class/Object

fs2.async

Promise

Related Docs: object Promise | package async

Permalink

final class Promise[F[_], A] extends AnyRef

A purely functional synchronisation primitive.

When created, a Promise is empty. It can then be completed exactly once, and never be made empty again.

get on an empty Promise will block until the Promise is completed. get on a completed Promise will always immediately return its content.

complete(a) on an empty Promise will set it to a, and notify any and all readers currently blocked on a call to get. complete(a) on a Promise that's already been completed will not modify its content, and result in a failed F.

Albeit simple, Promise can be used in conjunction with Ref to build complex concurrent behaviour and data structures like queues and semaphores.

Finally, the blocking mentioned above is semantic only, no actual threads are blocked by the implementation.

Source
Promise.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Promise
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  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. def +(other: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from Promise[F, A] to any2stringadd[Promise[F, A]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Promise[F, A], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from Promise[F, A] to ArrowAssoc[Promise[F, A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def cancellableGet: F[(F[A], F[Unit])]

    Permalink

    Like get but returns an F[Unit] that can be used to cancel the subscription.

  8. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def complete(a: A): F[Unit]

    Permalink

    If this Promise is empty, *synchronously* sets the current value to a, and notifies any and all readers currently blocked on a get.

    If this Promise is empty, *synchronously* sets the current value to a, and notifies any and all readers currently blocked on a get.

    Note that the returned action completes after the reference has been successfully set: use async.fork(r.complete) if you want asynchronous behaviour.

    If this Promise has already been completed, the returned action immediately fails with a Promise.AlreadyCompletedException. In the uncommon scenario where this behaviour is problematic, you can handle failure explicitly using attempt or any other ApplicativeError/MonadError combinator on the returned action.

    Satisfies: Promise.empty[F, A].flatMap(r => r.complete(a) *> r.get) == a.pure[F]

  10. def ensuring(cond: (Promise[F, A]) ⇒ Boolean, msg: ⇒ Any): Promise[F, A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Promise[F, A] to Ensuring[Promise[F, A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def ensuring(cond: (Promise[F, A]) ⇒ Boolean): Promise[F, A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Promise[F, A] to Ensuring[Promise[F, A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. def ensuring(cond: Boolean, msg: ⇒ Any): Promise[F, A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Promise[F, A] to Ensuring[Promise[F, A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: Boolean): Promise[F, A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Promise[F, A] to Ensuring[Promise[F, A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. final def eq(arg0: AnyRef): Boolean

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

    Permalink
    Definition Classes
    AnyRef → Any
  16. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. def formatted(fmtstr: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from Promise[F, A] to StringFormat[Promise[F, A]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  18. def get: F[A]

    Permalink

    Obtains the value of the Promise, or waits until it has been completed.

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  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. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  26. def timedGet(timeout: FiniteDuration, scheduler: Scheduler): F[Option[A]]

    Permalink

    Like get but if the Promise has not been completed when the timeout is reached, a None is returned.

  27. def toString(): String

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

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. def [B](y: B): (Promise[F, A], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from Promise[F, A] to ArrowAssoc[Promise[F, A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from Promise[F, A] to any2stringadd[Promise[F, A]]

Inherited by implicit conversion StringFormat from Promise[F, A] to StringFormat[Promise[F, A]]

Inherited by implicit conversion Ensuring from Promise[F, A] to Ensuring[Promise[F, A]]

Inherited by implicit conversion ArrowAssoc from Promise[F, A] to ArrowAssoc[Promise[F, A]]

Ungrouped