observable

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT 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

Index

Constants

View Source
const DefaultSubscriberBuffer = 128

DefaultSubscriberBuffer is the default buffer size for subscriber channels.

Variables

This section is empty.

Functions

This section is empty.

Types

type Observable

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

Observable is a generic fan-out event bus. It reads from a source channel and fans out to multiple subscribers.

func NewObservable

func NewObservable[T any](source <-chan T) *Observable[T]

NewObservable creates a new Observable and starts the fan-out goroutine.

func (*Observable[T]) Dropped

func (o *Observable[T]) Dropped() int64

Dropped returns the total number of messages dropped due to slow subscribers.

func (*Observable[T]) Subscribe

func (o *Observable[T]) Subscribe() (events <-chan T, unsub func())

Subscribe returns a channel of events and an unsubscribe function.

func (*Observable[T]) SubscribeWithBuffer

func (o *Observable[T]) SubscribeWithBuffer(size int) (events <-chan T, unsub func())

SubscribeWithBuffer is like Subscribe but lets the caller choose the subscriber channel buffer size. size <=0 falls back to DefaultSubscriberBuffer.

Jump to

Keyboard shortcuts

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