wsdrain

package
v0.0.0-...-6f0eb99 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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