wsdrain

package
v0.0.0-...-ae64afa Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

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 New

func New() *Registry

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.

func (*Registry) Track

func (r *Registry) Track(conn Conn) func()

Track registers conn and returns a function that removes it. The returned function is idempotent; call it (e.g. via defer) when the connection ends.

Jump to

Keyboard shortcuts

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