OxL Reference

10.3 Streams

Kind of rpcSignature
unaryrpc f(a: A) -> B
server-streamrpc f(a: A) -> stream<B>
client-streamrpc f(input: stream<A>) -> B
bidirpc f(input: stream<A>) -> stream<B>
  • The type is stream<T, E = never>. A remote stream has the errors E | NetError.
  • Generator: a function with the result stream<T, E> and yield in the body. Returning from the body ends the stream, fail e ends it with an error.
  • Locally a stream works as an asynchronous generator: items are passed to the consumer without serialisation.
  • for await x in s { … }: when the stream fails, the loop propagates the error like ? (the error MUST be included in the function's type); for await r in s.results() receives T | E without propagation.
  • Backpressure: the producer is suspended in yield when the consumer cannot keep up (locally — a buffer of 1; over the network — the @window credit window).
  • @resumable: every item gets a u64 offset; on a disconnect the client library reconnects and passes the last offset; the generator receives it in ctx.resumeFrom: u64?.
  • Pipe x |> f(args) means f(x, args); stream operators (filter, map, window, …) are functions of std.stream (part II).

yield-outside-stream

See also

Source: docs/spec/oxl-standard.en.md