Why?
UseCase: Can we use zio to setState of a component?
Ref Doc on zioµsiteRef scaladoc
.
.
What is a volatile var a:A
volatile means it is directly read-from/written-to the main memory, no cpu caching happens.
var means, the value a on the other end of the var, can be mutated in place to become a different A, by whoever can access the var. The var is still immutable at the typelevel, ie, its type can't be changed. It's value can be changed, but it will always conform to type A.
.
.
A mutable atomic reference for the IO monad. This is the IO equivalent of a volatile var, augmented with atomic operations, which make it useful as a reasonably efficient (if low-level) concurrency primitive.
Ref[A] models a mutable reference to a value of type A.
Mutable Reference Semantics: I have an address in my hand. The address can change. But it's guaranteed that, the reference will always lead to an a:A
Construction: final def make[A](a: A): UIO[Ref[A]]
Can be done via Ref.make(someA) where someA: A, flatmapping to an ra: Ref[A]
Get: Calling ra.get
Why? UseCase: Can we use zio to setState of a component?
Ref
Doc on zioµsiteRef
scaladoc. . What is a
volatile var a:A
volatile means it is directly read-from/written-to the main memory, no cpu caching happens. var means, the value a on the other end of the var, can be mutated in place to become a differentA
, by whoever can access the var. The var is still immutable at the typelevel, ie, its type can't be changed. It's value can be changed, but it will always conform to type A. . .Mutable Reference Semantics: I have an address in my hand. The address can change. But it's guaranteed that, the reference will always lead to an
a:A
Construction:
final def make[A](a: A): UIO[Ref[A]]
Can be done viaRef.make(someA)
wheresomeA: A
, flatmapping to anra: Ref[A]
Get: Callingra.get