Body.Stream #
This module defines a zero-buffer rendezvous body channel (Body.Stream) that supports
both sending and receiving chunks.
There is no queue and no capacity. A send waits for a receiver and a receive waits for a sender. At most one blocked producer and one blocked consumer are supported.
A zero-buffer rendezvous body channel that supports both sending and receiving chunks.
- state : Std.Mutex Channel.State
Instances For
Creates a rendezvous body stream.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Attempts to receive a chunk from the channel without blocking.
Returns some chunk only when a producer is already waiting. If the stream has been closed with a
terminal error, throws that error instead of returning none.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Non-blocking receive for the Body typeclass. Returns none when no producer is
waiting and the channel is still open, some (some chunk) when data is ready,
or some none at end-of-stream (channel closed with no pending producer).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Receives a chunk from the channel. Blocks until a producer sends one. Returns none if the channel
is closed and no producer is waiting. If the channel was closed with a terminal error
(via closeWithError) after all buffered chunks have been consumed, that error is thrown instead of EOF.
Equations
- stream.recv = do let __do_lift ← liftM (Std.Http.Body.Stream.recv'✝ stream) Std.Async.Async.ofAsyncTask __do_lift
Instances For
Closes the channel.
Equations
- stream.close = (Std.Http.Body.Stream.state✝ stream).atomically Std.Http.Body.Channel.close'✝
Instances For
Closes the channel only if no consumer is currently registered (i.e., the stream
was abandoned without being read). If a consumer is waiting, the close is skipped
so the pending recv can still receive data. Returns true if the stream was closed.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Closes the channel and records err as a terminal error. A subsequent recv that would have
returned end-of-stream surfaces the error instead; already buffered chunks are still delivered first.
This function does not overwrite an existing error.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Checks whether the channel is closed.
Equations
- stream.isClosed = (Std.Http.Body.Stream.state✝ stream).atomically do let __do_lift ← get pure (Std.Http.Body.Channel.State.closed✝ __do_lift)
Instances For
Gets the known size if available.
Equations
- stream.getKnownSize = (Std.Http.Body.Stream.state✝ stream).atomically do let __do_lift ← get pure (Std.Http.Body.Channel.State.knownSize✝ __do_lift)
Instances For
Sets known size metadata.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates a selector that resolves when a producer is waiting (or the channel closes).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Iterates over chunks until the channel closes.
Equations
- stream.forIn acc step = Std.Http.Body.Stream.forIn.loop✝ step stream acc
Instances For
Context-aware iteration over chunks until the channel closes.
Equations
- stream.forIn' acc step = Std.Http.Body.Stream.forIn'.loop✝ step stream acc
Instances For
Abstracts over how the next chunk is received, allowing readAll to work in both Async
(no cancellation) and ContextAsync (races with cancellation via doneSelector).
Receives the next chunk, stopping at EOF or (in
ContextAsync) when the context is cancelled.
Instances
Equations
- Std.Http.Body.Stream.instNextChunkAsync = { nextChunk := fun (stream : Std.Http.Body.Stream) => stream.recv }
Equations
- One or more equations did not get rendered due to their size.
Reads all remaining chunks and decodes them into α.
Works in both Async (reads until EOF, no cancellation) and ContextAsync (also stops if the
context is cancelled).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Drains all remaining chunks from the stream, discarding their contents.
If drainLimit is given, at most that many bytes are consumed; when the limit is exceeded the
stream is closed (via closeStream) and no error is raised.
Works in both Async (reads until EOF, no cancellation) and ContextAsync (also stops if the
context is cancelled).
Equations
- stream.drain drainLimit closeStream = Std.Http.Body.Stream.drain.loop✝ stream drainLimit closeStream 0
Instances For
Sends a chunk.
If incomplete := true, the chunk is buffered and collapsed with subsequent chunks, and is not
delivered to the receiver yet.
If incomplete := false, any buffered incomplete pieces are collapsed with this chunk and the
single merged chunk is sent.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Returns true when a consumer is currently blocked waiting for data.
Equations
Instances For
Creates a selector that resolves when consumer interest is present.
Returns true when a consumer is waiting, false when the channel closes first.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates a body from a producer function.
Returns the stream immediately and runs gen in a detached task.
The channel is closed when gen returns. If gen throws, the channel is closed with that terminal
error so consumers observe the failure instead of a clean end-of-stream.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates a body from a fixed byte array.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates an empty Stream body channel (already closed, no data).
Prefer Body.Empty when you need a concrete zero-cost type. Use this when the calling
context requires a Stream specifically.
Equations
- Std.Http.Body.empty = do let s ← Std.Http.Body.mkStream s.setKnownSize (some (Std.Http.Body.Length.fixed 0)) s.close pure s
Instances For
Equations
- Std.Http.Body.instForInAsyncStreamChunk = { forIn := fun {β : Type} => Std.Http.Body.Stream.forIn }
Equations
- Std.Http.Body.instForInContextAsyncStreamChunk = { forIn := fun {β : Type} => Std.Http.Body.Stream.forIn' }
Equations
- One or more equations did not get rendered due to their size.
Equations
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Builds a request with a streaming body generator.
Equations
- builder.stream gen = do let s ← Std.Http.Body.stream gen pure (builder.body s)
Instances For
Builds a response with a streaming body generator.
Equations
- builder.stream gen = do let s ← Std.Http.Body.stream gen pure (builder.body s)