transport

package
v0.1.30 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package transport deals with packet-like connections between endpoints. It includes helpers to create them from sockets or as derived concepts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadCh added in v0.1.27

func ReadCh[Out any](tr Transport) <-chan Out

ReadCh accepts the given transport and takes over its read handler to send messages on the passed channel. This continues until the Transport shuts down.

Types

type Transport

type Transport interface {
	// Read reads the next message available into the given target, e.g., by decoding.
	Read(any) error

	// Send sends the given message.
	// This may block, or not, and may always return nil (e.g., message put into queue rather than sent directly).
	Send(any) error

	// Context returns a context which is Done when the underlying connection has closed.
	Context() context.Context
}

func SocketJSON

func SocketJSON(ctx context.Context, sock *websocket.Conn) (t Transport, cancel context.CancelCauseFunc)

SocketJSON wraps an open websocket.Conn, converting it to an untyped Transport that reads and writes JSON. It derives a new Context which is canceled only if a Read/Send operation fails, but which also closes the socket itself. If the cancel method is called with a websocket.CloseError, the socket is closed in that way.

Jump to

Keyboard shortcuts

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