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

NameSignatureSynopsis
Control transactions
retrySTM.retry Signals that the current branch should retry once observed state changes.
orElseSTM.orElse left rightTries the left branch and falls back to the right branch when the left branch retries.
Run transactions
atomicallySTM.atomically transactionExecutes an STM transaction atomically within a flow while preserving retry/orElse coordination.

Control transactions

kind:membertask:control

retry

STM.retry
Member
Signals that the current branch should retry once observed state changes.

Returns

STM<'T>
kind:membertask:control

orElse

STM.orElse left right
Member
Tries the left branch and falls back to the right branch when the left branch retries.

Parameters

NameTypeDescription
leftSTM<'T>The primary STM transaction to attempt.
rightSTM<'T>The fallback STM transaction to run if the first one retries.

Returns

STM<'T>

Run transactions

kind:membertask:run

atomically

STM.atomically transaction
Member
Executes an STM transaction atomically within a flow while preserving retry/orElse coordination.

Parameters

NameTypeDescription
transactionSTM<'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)