Documentation
¶
Overview ¶
Package wsdrain tracks live WebSocket connections so they can be closed with a single status code when the server shuts down.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface {
Close(code websocket.StatusCode, reason string) error
}
Conn is the subset of *websocket.Conn the registry needs.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry tracks active connections. Construct one with New. All methods are safe for concurrent use and tolerate a nil receiver, so callers may pass a nil *Registry to disable tracking.
func (*Registry) CloseAll ¶
func (r *Registry) CloseAll(code websocket.StatusCode, reason string) int
CloseAll closes every tracked connection with the given code and reason and returns how many it closed. Connections are snapshotted under the lock and closed outside it. Close errors are ignored: the connection is being discarded regardless, and the first Close wins, so a later normal-closure from the connection's own teardown does not override the code sent here.