OxL Reference

error atomic-effects

error Standard: [§8.9]

What it means#

The body of atomic { ... } is a serialisable transaction that may be restarted on conflict, so it MUST be pure apart from TVar operations; a call with effects is an error (§8.9). Side effects could otherwise be repeated.

Example#

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

fn transfer(from: TVar<i64>, to: TVar<i64>, amt: i64) io {
  atomic {
    print("moving")      // <- atomic-effects (io inside a transaction)
    from.update(x => x - amt)
    to.update(x => x + amt)
  }
}
error
atomic-effects

How to fix#

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

fn transfer(from: TVar<i64>, to: TVar<i64>, amt: i64) io {
  atomic {
    from.update(x => x - amt)
    to.update(x => x + amt)
  }
  print("moved")
}

Perform the side effects before or after the transaction. For a database transaction use atomic(db) { ... } (§11.2).

See also#

OxL 1.0.0-beta · Documentation version 1.0.0-beta© OxwaldLink · generated from the Standard, the std sources and the guides