eventbus

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 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

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("eventbus: closed")

ErrClosed is returned by Publish/Subscribe after Inmem.Close.

Functions

This section is empty.

Types

type EventBus

type EventBus interface {
	Publish(ctx context.Context, channel string, data []byte) error
	// Subscribe returns a receive-only channel of payloads and a close function. The caller must call close when done.
	Subscribe(ctx context.Context, channel string) (data <-chan []byte, closeFn func() error, err error)
	// Close releases bus resources and closes all subscriber channels. Idempotent.
	Close()
}

EventBus is pub/sub for agent events (streaming, approval fan-in). SDK runtimes use this internally; application code does not construct EventBus. Implementations may be in-memory, Redis-backed, or bridged from Temporal updates.

type Inmem

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

Inmem is a process-local pub/sub suitable for streaming and approval fan-in on one host.

mu is a RWMutex, not a plain Mutex: Publish holds RLock for its entire send loop (not just the subscriber-list snapshot) so that Subscribe/Unsubscribe/Close — which all take the exclusive Lock — cannot close a subscriber channel while Publish is still sending to it. Concurrent Publish calls still proceed in parallel (RLock is shared); only a close(ch) has to wait for in-flight publishes to finish.

func NewInmem

func NewInmem(l logger.Logger) *Inmem

NewInmem returns an EventBus backed by in-memory channels. Logger may be nil (logging disabled).

func (*Inmem) Close added in v0.3.0

func (c *Inmem) Close()

Close closes all subscriber channels and rejects further Publish/Subscribe. Idempotent; safe if individual closeFns run afterward.

func (*Inmem) Publish

func (c *Inmem) Publish(ctx context.Context, channel string, data []byte) error

Publish sends a copy of data to all subscribers of channel.

Holds RLock for the whole call (snapshot + every send), not just the snapshot: this is what keeps Unsubscribe/Close from calling close(ch) on a channel this call is still writing to (see the Inmem.mu doc). Without that, a subscriber unsubscribing mid-publish would race a send against a close on the very same channel — a real data race per the Go memory model, not just a benign timing hazard, even though the runtime's panic on it is deterministic.

func (*Inmem) Subscribe

func (c *Inmem) Subscribe(ctx context.Context, channel string) (<-chan []byte, func() error, error)

Subscribe registers a new subscriber for channel.

Jump to

Keyboard shortcuts

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