error atomic-effects
Тело atomic должно быть чистым, кроме операций TVar.
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#
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#
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).