compare And Set
Atomically updates the TVar only if the current value matches expected.
Example:
val tvar = TVar.new("initial")
val swapped = tvar.compareAndSet("initial", "updated") // true
val failed = tvar.compareAndSet("initial", "other") // false (already "updated")Content copied to clipboard
Return
true if the update occurred, false otherwise
Parameters
expected
the value to compare against
new
the value to set if the comparison succeeds