Imp.Streaming.Messages.StreamListener (Imp v0.5.0)

Copy Markdown View Source

Incremental, transparent stream observer.

attach/2 always yields the source events unchanged. :on_event observes those events as they are pulled. When :signature_field_name (or its :field alias) and :on_chunk are configured, the listener also extracts that adapter field incrementally and reports normalized StreamResponse chunks without waiting for the complete response.

:adapter selects the built-in Chat, JSON, or XML framing and defaults to Imp.Adapter.Chat. Custom adapters can opt in explicitly with a bounded, exact-delimiter :framing map containing non-empty :start and :end binaries. Delimiters are data, never regular expressions or callbacks.

:on_status receives exactly one :started event and one terminal event: :completed, :error, or :cancelled. Early downstream halt is cancellation. Chat, XML, and custom framing retain only possible delimiter prefixes. JSON uses a bytewise lexer and retains only depth, escape, and bounded key-match state, so listener memory does not grow with response size.

Summary

Functions

attach(listener, enumerable)

new(opts \\ [])

record(listener, event)