sealed abstract class ZFiberRef[+EA, +EB, -A, +B] 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 result <- child.join } yield result
Here result will be equal to "Hi!" since changed 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, 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
- ZFiberRef[EA, EB, A, B]
- Alphabetic
- By Inheritance
- ZFiberRef
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def fold[EC, ED, C, D](ea: (EA) => EC, eb: (EB) => ED, ca: (C) => Either[EC, A], bd: (B) => Either[ED, D]): ZFiberRef[EC, ED, C, D]
Folds over the error and value types of the
ZFiberRef.Folds over the error and value types of the
ZFiberRef. This is a highly polymorphic method that is capable of arbitrarily transforming the error and value types of theZFiberRef. For most use cases one of the more specific combinators implemented in terms offoldwill be more ergonomic but this method is extremely useful for implementing new combinators. - abstract def foldAll[EC, ED, C, D](ea: (EA) => EC, eb: (EB) => ED, ec: (EB) => EC, ca: (C) => (B) => Either[EC, A], bd: (B) => Either[ED, D]): ZFiberRef[EC, ED, C, D]
Folds over the error and value types of the
ZFiberRef, allowing access to the state in transforming thesetvalue.Folds over the error and value types of the
ZFiberRef, allowing access to the state in transforming thesetvalue. This is a more powerful version offoldbut requires unifying the error types. - abstract def get: IO[EB, B]
Reads the value associated with the current fiber.
Reads the value associated with the current fiber. Returns initial value if no value was
setor inherited from parent. - abstract def initialValue: Either[EB, B]
Returns the initial value or error.
- abstract def locally[R, EC >: EA, C](value: A)(use: ZIO[R, EC, C]): ZIO[R, EC, C]
Returns an
IOthat runs withvaluebound to the current fiber.Returns an
IOthat runs withvaluebound to the current fiber.Guarantees that fiber data is properly restored via
acquireRelease. - abstract def set(value: A): IO[EA, Unit]
Sets the value associated with the current fiber.
Concrete 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 clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def collect[C](pf: PartialFunction[B, C]): ZFiberRef[EA, Option[EB], A, C]
Maps and filters the
getvalue of theZFiberRefwith the specified partial function, returning aZFiberRefwith agetvalue that succeeds with the result of the partial function if it is defined or else fails withNone. - def contramap[C](f: (C) => A): ZFiberRef[EA, EB, C, B]
Transforms the
setvalue of theZFiberRefwith the specified function. - def contramapEither[EC >: EA, C](f: (C) => Either[EC, A]): ZFiberRef[EC, EB, C, B]
Transforms the
setvalue of theZFiberRefwith the specified fallible function. - def dimap[C, D](f: (C) => A, g: (B) => D): ZFiberRef[EA, EB, C, D]
Transforms both the
setandgetvalues of theZFiberRefwith the specified functions. - def dimapEither[EC >: EA, ED >: EB, C, D](f: (C) => Either[EC, A], g: (B) => Either[ED, D]): ZFiberRef[EC, ED, C, D]
Transforms both the
setandgetvalues of theZFiberRefwith the specified fallible functions. - def dimapError[EC, ED](f: (EA) => EC, g: (EB) => ED): ZFiberRef[EC, ED, A, B]
Transforms both the
setandgeterrors of theZFiberRefwith the specified functions. - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def filterInput[A1 <: A](f: (A1) => Boolean): ZFiberRef[Option[EA], EB, A1, B]
Filters the
setvalue of theZFiberRefwith the specified predicate, returning aZFiberRefwith asetvalue that succeeds if the predicate is satisfied or else fails withNone. - def filterOutput(f: (B) => Boolean): ZFiberRef[EA, Option[EB], A, B]
Filters the
getvalue of theZFiberRefwith the specified predicate, returning aZFiberRefwith agetvalue that succeeds if the predicate is satisfied or else fails withNone. - 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()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def map[C](f: (B) => C): ZFiberRef[EA, EB, A, C]
Transforms the
getvalue of theZFiberRefwith the specified function. - def mapEither[EC >: EB, C](f: (B) => Either[EC, C]): ZFiberRef[EA, EC, A, C]
Transforms the
getvalue of theZFiberRefwith the specified fallible function. - 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 readOnly: ZFiberRef[EA, EB, Nothing, B]
Returns a read only view of the
ZFiberRef. - 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()
- def writeOnly: ZFiberRef[EA, Unit, A, Nothing]
Returns a write only view of the
ZFiberRef.