rpcstream

package
v0.109.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package rpcstream holds helpers shared by the engine's streaming RPC handlers.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("stream is closed")

ErrClosed is returned by Send once the handler that owns the stream has returned.

Functions

func WithAbort

func WithAbort(ctx context.Context, abort func()) context.Context

WithAbort returns a context carrying a function that interrupts a write blocked on the stream's transport, for example by expiring its write deadline. The server sets it for every request; NewSender picks it up.

Types

type Sender

type Sender[T any] struct {
	// contains filtered or unexported fields
}

Sender serializes sends on a server stream and rejects sends once the owning handler has returned.

Handlers hand their stream to other goroutines (the dispatcher sends assigned actions from message queue consumers, subscriptions send from fan-out goroutines). The HTTP/2 server panics on a write that arrives after the handler has returned, so every handler that shares its stream must wrap it in a Sender and defer Close: Close turns every later Send into ErrClosed and does not return while a Send is still writing. A Send to a peer that has stopped reading is interrupted after a short grace period, so a handler can always return.

func NewSender

func NewSender[T any](ctx context.Context, stream Stream[T]) *Sender[T]

NewSender wraps stream. ctx is the handler's context.

func (*Sender[T]) Close

func (s *Sender[T]) Close()

Close marks the stream as finished. It must be called before the handler returns, normally with defer.

func (*Sender[T]) Send

func (s *Sender[T]) Send(msg *T) error

type Stream

type Stream[T any] interface {
	Send(*T) error
}

Stream is the sending half of a server stream, satisfied by *connect.ServerStream[T] and *connect.BidiStream[Req, T].

Jump to

Keyboard shortcuts

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