eventstream

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEventStreamClosed = errors.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) *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.

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