aggstream

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package aggstream provides the plumbing for aggregated JSON-lines streams: endpoints that multiplex per-environment events from the local environment and every remote environment over a single HTTP response, so the browser needs one connection regardless of environment count.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReconcileEnvironmentPollers

func ReconcileEnvironmentPollers(
	ctx context.Context,
	lister RemoteEnvironmentLister,
	reconcileInterval time.Duration,
	streamLabel string,
	runPoller func(ctx context.Context, environmentID string),
)

ReconcileEnvironmentPollers keeps one poller goroutine per enabled remote environment, re-listing periodically so environments added or removed while the stream is open are picked up without a reconnect. It returns when the stream context is canceled, after every poller has exited.

func Run

func Run[T any](
	ctx context.Context,
	encoder *json.Encoder,
	flush func(),
	buffer int,
	heartbeatInterval time.Duration,
	makeHeartbeat func() T,
	producers ...func(ctx context.Context, events chan<- T),
)

Run drives a JSON-lines aggregated stream: it fans in events from the given producers over a single buffered channel and multiplexes them onto the response together with periodic heartbeats. It returns when the request context is canceled or the response writer fails.

func Send

func Send[T any](ctx context.Context, events chan<- T, event T) bool

Send forwards an event to the stream's event channel, giving up when the stream is shutting down so producers can never block.

Types

type RemoteEnvironmentLister

type RemoteEnvironmentLister interface {
	ListRemoteEnvironmentIDs(ctx context.Context) ([]string, error)
}

RemoteEnvironmentLister lists the remote environment IDs an aggregated stream should cover; it decouples this package from the environment service.

Jump to

Keyboard shortcuts

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