Documentation
¶
Overview ¶
Package sse writes a server sent event stream. It is internal, because the ds package and the htmx package own the shapes that an application writes. See the SDD, S12.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("sse: the client closed the stream")
ErrClosed states that the client closed the connection. A stream returns it after a disconnect, so a handler stops its work and returns.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// Name is the event type. An empty name writes no event line, so the
// client reads the frame as a message.
Name string
// ID is the identifier of the frame. An empty value writes no id line.
ID string
// Retry is the reconnection delay. A zero value writes no retry line.
Retry time.Duration
// Data holds one data line for each element. A line that holds a new
// line becomes two lines, because a frame cannot carry one.
Data []string
}
Event is one frame.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream writes frames to one client.
func New ¶
New starts a stream. It writes the headers of the stream and flushes them, so the client opens at once.
It returns an error when the writer cannot flush. A writer that buffers the whole response cannot stream, and the fault must appear before the handler writes a frame.
func (*Stream) Done ¶
func (s *Stream) Done() <-chan struct{}
Done returns a channel that closes when the client disconnects. A handler that waits for work selects on it, so no goroutine stays behind.