Packages

abstract class SignallingRef[F[_], A] extends Ref[F, A] with Signal[F, A]

Pure holder of a single value of type A that can be both read and updated in the effect F.

The update methods have the same semantics as Ref, as well as propagating changes to discrete (with a last-update-wins policy in case of very fast updates).

The access method differs slightly from Ref in that the update function, in the presence of discrete, can return false and need looping even without any other writers.

Source
Signal.scala
Linear Supertypes
Signal[F, A], Ref[F, A], RefSink[F, A], RefSource[F, A], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. SignallingRef
  2. Signal
  3. Ref
  4. RefSink
  5. RefSource
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new SignallingRef()

Abstract Value Members

  1. abstract def access: F[(A, (A) ⇒ F[Boolean])]
    Definition Classes
    Ref
  2. abstract def continuous: Stream[F, A]

    Returns a stream of the current value of the signal.

    Returns a stream of the current value of the signal. An element is always available -- on each pull, the current value is supplied.

    Definition Classes
    Signal
  3. abstract def discrete: Stream[F, A]

    Returns a stream of the updates to this signal.

    Returns a stream of the updates to this signal.

    Updates that are very close together may result in only the last update appearing in the stream. If you want to be notified about every single update, use a Queue or Channel instead.

    Definition Classes
    Signal
  4. abstract def get: F[A]

    Asynchronously gets the current value of this Signal.

    Asynchronously gets the current value of this Signal.

    Definition Classes
    Signal
  5. abstract def modify[B](f: (A) ⇒ (A, B)): F[B]
    Definition Classes
    Ref
  6. abstract def modifyState[B](state: State[A, B]): F[B]
    Definition Classes
    Ref
  7. abstract def set(a: A): F[Unit]
    Definition Classes
    RefSink
  8. abstract def tryModify[B](f: (A) ⇒ (A, B)): F[Option[B]]
    Definition Classes
    Ref
  9. abstract def tryModifyState[B](state: State[A, B]): F[Option[B]]
    Definition Classes
    Ref
  10. abstract def tryUpdate(f: (A) ⇒ A): F[Boolean]
    Definition Classes
    Ref
  11. abstract def update(f: (A) ⇒ A): F[Unit]
    Definition Classes
    Ref

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. def getAndSet(a: A): F[A]
    Definition Classes
    Ref
  10. def getAndUpdate(f: (A) ⇒ A): F[A]
    Definition Classes
    Ref
  11. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. def mapK[G[_]](f: ~>[F, G])(implicit F: Functor[F]): Ref[G, A]
    Definition Classes
    Ref
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  19. def toString(): String
    Definition Classes
    AnyRef → Any
  20. def updateAndGet(f: (A) ⇒ A): F[A]
    Definition Classes
    Ref
  21. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  24. def waitUntil(p: (A) ⇒ Boolean)(implicit F: Concurrent[F]): F[Unit]

    Returns when the condition becomes true, semantically blocking in the meantime.

    Returns when the condition becomes true, semantically blocking in the meantime.

    This method is particularly useful to transform naive, recursive polling algorithms on the content of a Signal/ SignallingRef into semantically blocking ones. For example, here's how to encode a very simple cache with expiry, pay attention to the definition of view:

    trait Refresh[F[_], A] {
      def get: F[A]
    }
    object Refresh {
      def create[F[_]: Temporal, A](
        action: F[A],
        refreshAfter: A => FiniteDuration,
        defaultExpiry: FiniteDuration
      ): Resource[F, Refresh[F, A]] =
        Resource
          .eval(SignallingRef[F, Option[Either[Throwable, A]]](None))
          .flatMap { state =>
            def refresh: F[Unit] =
              state.set(None) >> action.attempt.flatMap { res =>
                val t = res.map(refreshAfter).getOrElse(defaultExpiry)
                state.set(res.some) >> Temporal[F].sleep(t) >> refresh
              }
    
            def view = new Refresh[F, A] {
              def get: F[A] = state.get.flatMap {
                case Some(res) => Temporal[F].fromEither(res)
                case None => state.waitUntil(_.isDefined) >> get
              }
            }
    
            refresh.background.as(view)
          }
    }

    Note that because Signal prioritizes the latest update when its state is updating very quickly, completion of the F[Unit] might not trigger if the condition becomes true and then false immediately after.

    Therefore, natural use cases of waitUntil tend to fall into two categories: - Scenarios where conditions don't change instantly, such as periodic timed processes updating the Signal/SignallingRef. - Scenarios where conditions might change instantly, but the p predicate is monotonic, i.e. if it tests true for an event, it will test true for the following events as well. Examples include waiting for a unique ID stored in a Signal to change, or waiting for the value of the Signal of an ordered Stream[IO, Int] to be greater than a certain number.

    Definition Classes
    Signal

Inherited from Signal[F, A]

Inherited from Ref[F, A]

Inherited from RefSink[F, A]

Inherited from RefSource[F, A]

Inherited from AnyRef

Inherited from Any

Ungrouped