STMModule

PackageAxial

Summary

NameSignatureSynopsis
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.
atomicallySTM.atomically transactionExecutes an STM transaction atomically within a flow while preserving retry/orElse coordination.

retry

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

Returns

STM<'T>

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>

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)