observable

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrObserverClosed = errorsmod.Register(codespace, 1, "observer is closed")
)

Functions

This section is empty.

Types

type Error

type Error = Observable[error]

type Observable

type Observable[V any] interface {
	// Subscribe returns an observer which is notified when the publishCh channel
	// receives a value.
	// The order the values published by the subscription is FIFO.
	Subscribe(context.Context) Observer[V]
	// UnsubscribeAll unsubscribes and removes all observers from the observable.
	UnsubscribeAll()
}

Observable is a generic interface that allows multiple subscribers to be notified of new values asynchronously. It is analogous to a publisher in a "Fan-Out" system design.

type Observer

type Observer[V any] interface {
	// Unsubscribe closes the subscription channel and removes the subscription from
	// the observable.
	Unsubscribe()
	// Ch returns a receive-only subscription channel.
	Ch() <-chan V
	// IsClosed returns true if the observer has been unsubscribed.
	// A closed observer cannot be reused.
	IsClosed() bool
}

Observer is a generic interface that provides access to the notified channel and allows unsubscribing from an Observable. It is analogous to a subscriber in a "Fan-Out" system design.

type ReplayObservable

type ReplayObservable[V any] interface {
	Observable[V]
	// Last synchronously returns the last n values from the replay buffer with
	// LIFO ordering
	Last(ctx context.Context, n int) []V
}

ReplayObservable is an observable which replays the last n values published to new observers, before publishing new values to observers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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