kw atomic
Reserved keyword
The list of words: §1.4
Syntax
Primary = Literal | Path | "it" | "self" | "(" Expr { "," Expr } ")" | ListLit | MapLit
| StructLit | Lambda | Block | If | Match | For | While | Loop | Scope | Select | Query
| "spawn" ( Postfix | Block ) | "await" Unary | "atomic" [ "(" Args ")" ] Block
| "return" [ Expr ] | "fail" Expr | "yield" Expr | "respond" Expr | "break" [ Label ] [ Expr ]
| "continue" [ Label ] | "emit" Path "(" Expr ")" | "unsafe" Block | "blocking" Block
| "comptime" Block | "." Ident [ "(" [ Args ] ")" ] ;Grammar: App. A
Defined in
- 8.9 Software transactional memory — atomic { … } executes the body as a serialisable transaction over TVars.
- 11.2 Database transaction — The body is executed in a transaction of the database db.
- 11.1 Kinds of transactions — Kinds of transactions
- 10.5 Topics — cluster-wide fan-out — A topic is a distributed broadcast with storage in the built-in storage.
- 12.8 Built-in storage and tables — The storage is on every node of the journal role, replication is Raft per shard.
- 1.4 Keywords — Reserved (cannot be used as names)
Examples
static balances: Map<AccountId, TVar<Money>> = …
atomic {
let a = balances[from].get()
check(a >= amt) // otherwise the transaction waits for a change and retries
balances[from].set(a - amt)
balances[to].update(.add(amt))
}— 8.9 Software transactional memory
atomic(db) {
db.insert(order)
db.update(User, uid) { ordersCount += 1 }
emit OrderEvents(OrderEvent.Created(order.id))
}Related diagnostics
atomic-effects, atomic-db-effects, cross-shard-tx, topic-without-journal, query-not-sql, shard-count-clamped, table-schema