OxL Reference

kw spawn

Reserved keyword

The list of words: §1.4

Syntax

ebnf
Primary     = Literal | Path | "it" | "self" | "(" Expr { "," Expr } ")" | ListLit | MapLit
            | StructLit | Lambda | Block | If | Match | For | While | Loop | Scope | Select | Query
            | "spawn" ( Postfix | Block ) | "await" Unary | "atomic" [ "(" Args ")" ] Block
            | "return" [ Expr ] | "fail" Expr | "yield" Expr | "respond" Expr | "break" [ Label ] [ Expr ]
            | "continue" [ Label ] | "emit" Path "(" Expr ")" | "unsafe" Block | "blocking" Block
            | "comptime" Block | "." Ident [ "(" [ Args ] ")" ] ;

Grammar: App. A

Defined in

  • 10.4 Broadcast — local fan-out — Broadcast<T> delivers every published item to all current subscribers.
  • 8.3 Task — Task<T, E> is a lazy computation.
  • 8.5 Structured concurrency — spawn is allowed only lexically inside scope { …
  • 8.8 Local actors — Messages are processed strictly one at a time, in the order of arrival from each sender.
  • 5.7 Lambdas and closures — .field and .method(args) in argument position are shorthand for a lambda with one parameter.
  • 6.3 Calling suspendable functions — A call of a suspendable function in statement position or in an ordinary expression executes immediately; the current task waits for the res
  • 7.3 Transfer between tasks — A value is transferable between tasks (into spawn, into a channel, into an actor message) if its type contains no Rc, no borrows and no non-
  • 8.4 Chains — A chain links asynchronous steps so that either the whole chain is executed or the first unhandled error is returned.

Examples

oxl
let prices = Broadcast<Tick>(buffer: TICK_BUFFER, slow: .DropOldest, replay: 1)

scope {
  spawn { for await t in Exchange.feed() { prices.publish(t) } }
  spawn { for await t in prices.subscribe() { ui.render(t) } }
  spawn { for await t in prices.subscribe() { stats.add(t) } }
}

impl Market {
  rpc ticks() -> stream<Shared<Tick>, Lagged> => prices.subscribe()   // for every client
}

— 10.4 Broadcast — local fan-out

oxl
let (a, b) = scope {
  let ha = spawn loadA()
  let hb = spawn loadB()
  (ha.join()?, hb.join()?)
}

— 8.5 Structured concurrency

Related diagnostics

task-reuse, spawn-outside-scope, actor-cycle, send, it-outside-chain

See also