OxL Reference

fn enter

Start of step k (0-based) with the value v of the previous one: stops (Timeout) when the saga was cancelled or is being compensated from this step on, records the cursor, and sets the idempotency key of the step to sagaId#(k+1).

Example:

oxl✓ checked in CI
@error data Boom { m: str }

service Bank {
  @public @idempotent rpc hold(n: u64) -> u64
  @public @idempotent rpc unhold(n: u64) -> () | Boom
  @public @idempotent rpc refuse(n: u64) -> u64 | Boom
}

impl Bank {
  rpc hold(n) => n
  rpc unhold(n) { fail Boom{ m: "bank is down" } }
  rpc refuse(n) { fail Boom{ m: "no" } }
}

// the second step fails and its compensation never succeeds: the saga becomes stuck
saga pay(n: u64) -> u64 {
  Bank.hold(n)   undo h => Bank.unhold(h)
  -> Bank.refuse(n)
}

fn main() io, net, time, db {
  match pay(1) {
    u64 v => print("done {v}")
    Boom b => print("step failed: {b.m}")
    CompensationFailed c => print("stuck at step {c.step}")
    NetError e => print("net error")
  }
}
Output
stuck at step 1
pub(api) fn enter<T>(k: i64, v: T) -> T | Timeout  net, db, time

Since. 1.0.0-beta

Parameters

NameType
ki64
vT

Returns

T

Errors

  • Timeout @error
  • `Timeout` when the caller's deadline passed and the saga is being cancelled.

Effects

net, db, time

Defined in: std/saga/saga.oxl:437

See also