Response wrapper for streaming HTTP responses.
Contains an enumerable stream of events instead of a complete body. This is used for SSE (Server-Sent Events) and other streaming responses.
Fields
:stream- An enumerable that yields events (required):status- HTTP status code (required):headers- Response headers as a map (required):metadata- Additional metadata (optional, defaults to empty map)
Example
%StreamResponse{
stream: events,
status: 200,
headers: %{"content-type" => "text/event-stream"},
metadata: %{request_id: "req_123"}
}Usage
The stream can be consumed lazily:
{:ok, response} = StreamTransport.stream(request, context)
response.stream
|> Stream.each(fn event ->
IO.puts("Got event: #{inspect(event)}")
end)
|> Stream.run()Or collected into a list:
events = Enum.to_list(response.stream)
Summary
Functions
Cancel the underlying stream when supported by the transport.
Dispatch a single event to a handler module based on its type.
Map a stream of events through a handler module.
Return the latest Last-Event-ID value when available.
Types
@type t() :: %Pristine.Core.StreamResponse{ headers: map(), metadata: map(), status: integer(), stream: Enumerable.t() }
Functions
@spec cancel(t()) :: :ok
Cancel the underlying stream when supported by the transport.
@spec dispatch_event(Pristine.Streaming.Event.t(), module()) :: {:ok, term()} | {:error, term()} | term()
Dispatch a single event to a handler module based on its type.
@spec dispatch_stream(t(), module()) :: Enumerable.t()
Map a stream of events through a handler module.
Return the latest Last-Event-ID value when available.