Packages

trait FiberRef[A] extends Serializable

A FiberRef is ZIO's equivalent of Java's ThreadLocal. The value of a FiberRef is automatically propagated to child fibers when they are forked and merged back in to the value of the parent fiber after they are joined.

for {
  fiberRef <- FiberRef.make("Hello world!")
  child    <- fiberRef.set("Hi!").fork
  _        <- child.join
  result   <- fiberRef.get
} yield result

Here result will be equal to "Hi!" since changes made by a child fiber are merged back in to the value of the parent fiber on join.

By default the value of the child fiber will replace the value of the parent fiber on join but you can specify your own logic for how values should be merged.

for {
  fiberRef <- FiberRef.make(0, identity[Int], math.max)
  child    <- fiberRef.update(_ + 1).fork
  _        <- fiberRef.update(_ + 2)
  _        <- child.join
  value    <- fiberRef.get
} yield value

Here value will be 2 as the value in the joined fiber is lower and we specified max as our combining function.

Self Type
FiberRef[A]
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FiberRef
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. abstract type Patch

    The type of the patch that describes updates to the value of the FiberRef.

    The type of the patch that describes updates to the value of the FiberRef. In the simple case this will just be a function that sets the value of the FiberRef. In more complex cases this will describe an update to a piece of a whole value, allowing updates to the value by different fibers to be combined in a compositional way when those fibers are joined.

  2. type Value = A

    The type of the value of the FiberRef.

Abstract Value Members

  1. abstract def combine(first: Patch, second: Patch): Patch

    Combines two patches to produce a new patch that describes the updates of the first patch and then the updates of the second patch.

    Combines two patches to produce a new patch that describes the updates of the first patch and then the updates of the second patch. The combine operation should be associative. In addition, if the combine operation is commutative then joining multiple fibers concurrently will result in deterministic FiberRef values.

  2. abstract def diff(oldValue: Value, newValue: Value): Patch

    Constructs a patch describing the updates to a value from an old value and a new value.

  3. abstract def fork: Patch

    The initial patch that is applied to the value of the FiberRef when a new fiber is forked.

  4. abstract def initial: Value

    The initial value of the FiberRef.

  5. abstract def join(oldValue: Value, newValue: Value): Value
  6. abstract def patch(patch: Patch)(oldValue: Value): Value

    Applies a patch to an old value to produce a new value that is equal to the old value with the updates described by the patch.

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 asThreadLocal(implicit trace: Trace, unsafe: Unsafe): UIO[ThreadLocal[A]]

    Returns a ThreadLocal that can be used to interact with this FiberRef from side effecting code.

    Returns a ThreadLocal that can be used to interact with this FiberRef from side effecting code.

    This feature is meant to be used for integration with side effecting code, that needs to access fiber specific data, like MDC contexts and the like. The returned ThreadLocal will be backed by this FiberRef on all threads that are currently managed by ZIO when this feature is enabled using Runtime.enableCurrentFiber, and behave like an ordinary ThreadLocal on all other threads.

  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  7. def delete(implicit trace: Trace): UIO[Unit]
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  10. def get(implicit trace: Trace): UIO[A]

    Reads the value associated with the current fiber.

    Reads the value associated with the current fiber. Returns initial value if no value was set or inherited from parent.

  11. final def getAndSet(newValue: A)(implicit trace: Trace): UIO[A]

    Atomically sets the value associated with the current fiber and returns the old value.

  12. final def getAndUpdate(f: (A) => A)(implicit trace: Trace): UIO[A]

    Atomically modifies the FiberRef with the specified function and returns the old value.

  13. final def getAndUpdateSome(pf: PartialFunction[A, A])(implicit trace: Trace): UIO[A]

    Atomically modifies the FiberRef with the specified partial function and returns the old value.

    Atomically modifies the FiberRef with the specified partial function and returns the old value. If the function is undefined on the current value it doesn't change it.

  14. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. def getWith[R, E, B](f: (A) => ZIO[R, E, B])(implicit trace: Trace): ZIO[R, E, B]

    Gets the value associated with the current fiber and uses it to run the specified effect.

  16. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  17. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  18. def locally[R, E, B](newValue: A)(zio: ZIO[R, E, B])(implicit trace: Trace): ZIO[R, E, B]

    Returns a ZIO that runs with value bound to the current fiber.

    Returns a ZIO that runs with value bound to the current fiber.

    Guarantees that fiber data is properly restored via acquireRelease.

  19. final def locallyScoped(value: A)(implicit trace: Trace): ZIO[Scope, Nothing, Unit]

    Returns a scoped workflow that sets the value associated with the curent fiber to the specified value and restores it to its original value when the scope is closed.

  20. final def locallyScopedWith(f: (A) => A)(implicit trace: Trace): ZIO[Scope, Nothing, Unit]

    Returns a scoped workflow that updates the value associated with the current fiber using the specified function and restores it to its original value when the scope is closed.

  21. final def locallyWith[R, E, B](f: (A) => A)(zio: ZIO[R, E, B])(implicit trace: Trace): ZIO[R, E, B]

    Returns a ZIO that runs with f applied to the current fiber.

    Returns a ZIO that runs with f applied to the current fiber.

    Guarantees that fiber data is properly restored via acquireRelease.

  22. def modify[B](f: (A) => (B, A))(implicit trace: Trace): UIO[B]

    Atomically modifies the FiberRef with the specified function, which computes a return value for the modification.

    Atomically modifies the FiberRef with the specified function, which computes a return value for the modification. This is a more powerful version of update.

  23. final def modifySome[B](default: B)(pf: PartialFunction[A, (B, A)])(implicit trace: Trace): UIO[B]

    Atomically modifies the FiberRef with the specified partial function, which computes a return value for the modification if the function is defined in the current value otherwise it returns a default value.

    Atomically modifies the FiberRef with the specified partial function, which computes a return value for the modification if the function is defined in the current value otherwise it returns a default value. This is a more powerful version of updateSome.

  24. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  25. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  26. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  27. final def reset(implicit trace: Trace): UIO[Unit]
  28. def set(value: A)(implicit trace: Trace): UIO[Unit]

    Sets the value associated with the current fiber.

  29. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  30. def toString(): String
    Definition Classes
    AnyRef → Any
  31. def update(f: (A) => A)(implicit trace: Trace): UIO[Unit]

    Atomically modifies the FiberRef with the specified function.

  32. final def updateAndGet(f: (A) => A)(implicit trace: Trace): UIO[A]

    Atomically modifies the FiberRef with the specified function and returns the result.

  33. final def updateSome(pf: PartialFunction[A, A])(implicit trace: Trace): UIO[Unit]

    Atomically modifies the FiberRef with the specified partial function.

    Atomically modifies the FiberRef with the specified partial function. If the function is undefined on the current value it doesn't change it.

  34. final def updateSomeAndGet(pf: PartialFunction[A, A])(implicit trace: Trace): UIO[A]

    Atomically modifies the FiberRef with the specified partial function.

    Atomically modifies the FiberRef with the specified partial function. If the function is undefined on the current value it returns the old value without changing it.

  35. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  36. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  37. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped