STMUnion
PackageAxial
STM
STM<'T> is a composable transaction: a value describing reads and writes that commit together. Compose transactions
with stm { } before running them atomically. Read the STM guide for retry and
orElse behavior.
Signature reference
| Function | Signature | Description |
|---|---|---|
retry |
STM<'T> |
Requests that the current branch waits and reruns after a committed change. |
orElse |
STM<'T> -> STM<'T> -> STM<'T> |
Falls back to a second branch when the first branch retries. |
atomically |
STM<'T> -> Flow<'env, 'none, 'T> |
Executes a composed transaction as an atomic flow. |
Specification
Kind
Union
Members
3
Examples
0
retrySignature
STM.retry
orElseSignature
STM.orElse left right
atomicallySignature
STM.atomically transaction
Summary
| Name | Signature | Synopsis |
|---|---|---|
| Operations | ||
| retry | STM.retry | Signals that the current branch should retry once observed state changes. |
| orElse | STM.orElse left right | Tries the left branch and falls back to the right branch when the left branch retries. |
| atomically | STM.atomically transaction | Executes an STM transaction atomically within a flow while preserving retry/orElse coordination. |
Operations
kind:member
kind:member
kind:member
Executes an STM transaction atomically within a flow while preserving retry/orElse coordination.
Parameters
| Name | Type | Description |
|---|---|---|
| transaction | STM<'T> | The STM transaction to execute. |
Returns
Flow<'env, 'none, 'T>
Verification Examples
let transfer (fromAcc: TRef<int>) (toAcc: TRef<int>) amount =
stm {
let! bal = TRef.get fromAcc
if bal < amount then do! STM.retry
do! TRef.set (bal - amount) fromAcc
do! TRef.update (fun b -> b + amount) toAcc
}
let flow = STM.atomically (transfer acc1 acc2 100)
