with TVar
Creates a TVar with initial value and immediately uses it in a transaction.
Convenience function for cases where you need a short-lived transactional variable.
Example:
val result = withTVar(0) { tvar ->
tvar.write(tvar.read() + 42)
tvar.read()
} // 42Content copied to clipboard
Return
the result of the transaction
Parameters
initial
the initial value for the TVar
block
the STM transaction block that receives the created TVar