OxL Справочник OxL
РусскийEnglish

src/main.oxl

oxl
use self.bank { Bank, Account, transfer, Insufficient, Blocked }

fn show(label: str, r: i64 | Insufficient | Blocked | CompensationFailed | NetError) io {
  match r {
    i64 b => print("{label}: ok, target balance {b}")
    Insufficient e => print("{label}: insufficient funds ({e.balance})")
    Blocked e => print("{label}: account {e.id} is blocked, debit compensated")
    CompensationFailed _ => print("{label}: stuck")
    NetError _ => print("{label}: network error")
  }
}

fn main() io, net, time, db {
  Account(1).fund(100)!
  show("1 -> 2, 30", transfer(1, 2, 30))
  show("1 -> 99, 50", transfer(1, 99, 50))
  show("1 -> 2, 500", transfer(1, 2, 500))
  match Bank.balance(1) {
    i64 b => print("balance of 1: {b}")
    NetError _ => print("network error")
  }
}

Исходник: examples/bank-saga/src/main.oxl