10.3 Streams
| Kind of rpc | Signature |
|---|---|
| unary | rpc f(a: A) -> B |
| server-stream | rpc f(a: A) -> stream<B> |
| client-stream | rpc f(input: stream<A>) -> B |
| bidi | rpc f(input: stream<A>) -> stream<B> |
- The type is
stream<T, E = never>. A remote stream has the errorsE | NetError. - Generator: a function with the result
stream<T, E>andyieldin the body. Returning from the body ends the stream,fail eends 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()receivesT | Ewithout propagation.- Backpressure: the producer is suspended in
yieldwhen the consumer cannot keep up (locally — a buffer of 1; over the network — the@windowcredit window). @resumable: every item gets au64offset; on a disconnect the client library reconnects and passes the last offset; the generator receives it inctx.resumeFrom: u64?.- Pipe
x |> f(args)meansf(x, args); stream operators (filter,map,window, …) are functions ofstd.stream(part II).
Related diagnostics
See also
Source: docs/spec/oxl-standard.en.md