Documentation
¶
Index ¶
- Variables
- func IsConnError(err error) bool
- func IsUnrecoverableError(err error) bool
- type EventStream
- func (s *EventStream) InitiateStream(w http.ResponseWriter)
- func (s *EventStream) IsStreaming() bool
- func (s *EventStream) Send(ctx context.Context, payload []byte) error
- func (s *EventStream) SendRaw(ctx context.Context, payload []byte) error
- func (s *EventStream) Shutdown(shutdownCtx context.Context) error
- func (s *EventStream) Start(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
var ErrEventStreamClosed = errors.New("event stream closed")
Functions ¶
func IsConnError ¶
IsConnError checks if an error is related to client disconnection or context cancellation.
func IsUnrecoverableError ¶
Types ¶
type EventStream ¶
type EventStream struct {
// contains filtered or unexported fields
}
func NewEventStream ¶
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.