OxL Reference

method TVar.swap

Sets the value and returns the previous one.

Example:

oxl✓ checked in CI
use std.stm { TVar }

fn main() io {
  let v = TVar<i32>.new(1)
  let old = atomic { v.swap(2) }
  print("{old} {atomic { v.get() }}")
}
Output
1 2
pub(api) fn swap(value: T) -> T

Since. 1.0.0-beta

Parameters

NameType
valueT

Returns

T

Effects

none declared (pure unless the body says otherwise)

Defined in: std/stm/stm.oxl:141

See also