OxL Reference

kw to

Contextual keyword — select branches (§8.7)

The list of words: §1.4

Syntax

ebnf
SelArm      = ( "recv" Pattern "from" Expr | "send" Expr "to" Expr | "after" Expr | "else" ) "=>" Expr ;

Grammar: App. A

Defined in

Examples

oxl
let (tx, rx) = chan<Job>(cap: JOB_QUEUE)

select {
  recv job from rx  => process(job)
  send r to results => sent += 1
  after IDLE_TIMEOUT => log.info("idle")
  else              => tick()          // non-blocking variant
}

— 8.7 Channels and select

oxl
static balances: Map<AccountId, TVar<Money>> = …

atomic {
  let a = balances[from].get()
  check(a >= amt)                 // otherwise the transaction waits for a change and retries
  balances[from].set(a - amt)
  balances[to].update(.add(amt))
}

— 8.9 Software transactional memory

Related diagnostics

atomic-effects

See also