eventstream

package
v2.38.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (

	// SlowFlushThreshold is the duration after which a flush to the client is
	// considered slow and a warning is logged.
	SlowFlushThreshold = time.Millisecond * 500
)

Variables

View Source
var ErrEventStreamClosed = xerrors.New("event stream closed")

Functions

func IsConnError

func IsConnError(err error) bool

IsConnError checks if an error is related to client disconnection or context cancellation.

func IsUnrecoverableError

func IsUnrecoverableError(err error) bool

Types

type EventStream

type EventStream struct {
	// contains filtered or unexported fields
}

func NewEventStream

func NewEventStream(ctx context.Context, logger slog.Logger, pingPayload []byte, clk quartz.Clock) *EventStream

NewEventStream creates a new SSE stream, with an optional payload which is used to send pings every [pingInterval].

func (*EventStream) InitiateStream

func (s *EventStream) InitiateStream(w http.ResponseWriter)

InitiateStream initiates the SSE stream by sending headers and starting the ping ticker. This is safe to call multiple times as only the first call has any effect.

func (*EventStream) IsStreaming

func (s *EventStream) IsStreaming() bool

IsStreaming checks if the stream has been initiated, or when events are buffered which - when processed - will initiate the stream.

Note: there is a known race between the channel pop in Start and the subsequent InitiateStream call where this can briefly return false for a stream that's about to begin. Callers that use this to choose between JSON and SSE response formats can produce a malformed response under that race. Accepted until the MCP Gateway migration results in AI Gateway behaving like a reverse proxy, removing the inner agentic loop code. See https://github.com/coder/aibridge/issues/223 and https://github.com/coder/internal/issues/1524.

func (*EventStream) Send

func (s *EventStream) Send(ctx context.Context, payload []byte) error

Send enqueues an event in a non-blocking fashion, but if the channel is full then it will block.

func (*EventStream) SendRaw

func (s *EventStream) SendRaw(ctx context.Context, payload []byte) error

func (*EventStream) Shutdown

func (s *EventStream) Shutdown(shutdownCtx context.Context) error

Shutdown gracefully shuts down the stream, sending any supplementary events downstream if required. ONLY call this once all events have been submitted.

func (*EventStream) Start

func (s *EventStream) Start(w http.ResponseWriter, r *http.Request)

Start handles sending Server-Sent Event to the client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL