J.Concurrent.Ref

opaque type Ref[A]

Thread safe, minimal overhead reference based on java.util.concurrent.atomic.AtomicReference

Source
Ref.scala

Def

def change[A](f: A => A): A

Change value

Change value

Changes value based on function, which takes the old value and produces new one.

Returns the new value

Note. The provided function can be invoked and generate new value multiple times, and only last generated value will be returned (the others discarded).

Source
Ref.scala
inline def get[A]: A

Get target

Get target

Returns referenced object

Source
Ref.scala
inline def tryChange[A](old: A, value: A): Boolean

Try to replace the target value

Try to replace the target value

Provides the old and the new values

Returns true if value is successfully changed, false if old value is not longer current (was changed by other thread) and the change failed.

Source
Ref.scala