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 ¶
- func ReconcileEnvironmentPollers(ctx context.Context, lister RemoteEnvironmentLister, ...)
- func ReconcilePollersByKey[T any](ctx context.Context, listItems func(context.Context) ([]T, error), ...)
- func Run[T any](ctx context.Context, encoder *json.Encoder, flush func(), buffer int, ...)
- func Send[T any](ctx context.Context, events chan<- T, event T) bool
- type RemoteEnvironmentLister
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 ReconcilePollersByKey ¶ added in v2.2.0
func ReconcilePollersByKey[T any]( ctx context.Context, listItems func(context.Context) ([]T, error), keyFunc func(T) string, versionFunc func(T) string, reconcileInterval time.Duration, streamLabel string, runPoller func(ctx context.Context, item T), )
ReconcilePollersByKey keeps one poller goroutine per listed item, keyed by a stable item ID. If the same key is later returned with a different version, the old poller is replaced so callers can pass refreshed item metadata.
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.