signal

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 2 Imported by: ? modules, 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 signal provides typed, pull-based broadcasts for systems. A Hub stores signals by type, and each Reader maintains an independent cursor. Tick signals are readable during their tick and carried into the following frame window; frame signals are discarded at Hub.EndFrame.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub stores signals by type and rotates them between frame and tick windows.

func NewHub

func NewHub() *Hub

NewHub creates a Hub ready to collect frame signals.

func (*Hub) BeginFrame

func (h *Hub) BeginFrame()

BeginFrame starts collecting frame signals.

func (*Hub) Consumer

func (h *Hub) Consumer[T any](update func(ctx *core.Context, value T) error) core.SystemFunc

Consumer returns a system that calls update for each unread signal of type T in the current window. Each returned system has an independent Reader, so consumers do not compete for signals.

Use Hub.NewReader when one system reads several signal types or needs to manage the reader's lifetime directly.

func (*Hub) Emit

func (h *Hub) Emit[T any](value T)

Emit adds value to the current frame or tick window.

func (*Hub) EndFrame

func (h *Hub) EndFrame()

EndFrame discards remaining frame signals and starts tick collection.

func (*Hub) EndTick

func (h *Hub) EndTick()

EndTick moves tick signals into the frame window for readers to read.

func (*Hub) NewReader

func (h *Hub) NewReader[T any]() *Reader[T]

NewReader returns an independent reader for signals of type T. It starts at the beginning of the current window, so it can read signals already emitted in that window.

type Reader

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

Reader tracks an independent position while reading signals of type T. Sharing a Reader between consumers splits delivery between them.

func (*Reader[T]) Consume added in v0.4.0

func (r *Reader[T]) Consume(ctx *core.Context, update func(ctx *core.Context, value T) error) error

Consume calls update for each unread signal. A signal is consumed before update is called; on an error, later signals remain unread for the next call.

func (*Reader[T]) Next

func (r *Reader[T]) Next() (T, bool)

Next returns the next unread signal in the current window. The signal is consumed when returned. It reports false when the current batch is exhausted; signals emitted during that batch are available on the next read pass.

Jump to

Keyboard shortcuts

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