observable

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package observable is a simple generic implementation of the Observer design pattern.

Observables are identified by a string name which must be unique across an application. Calling the observable/Observe function both registers an observable by name and type, but also registers an observer by providing a notification function that is invoked when the value of the observable changes. Multiple observers can call observable/Observe to register for notifications concerning an existing observable; in this case, notification functions are called in the order in which they were registered.

To change the value of an observable, and to notify all observers by invoking their callback notification function, call the observable/Set function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Observe

func Observe[T any](name string, cb func(T)) error

Observe either registers a new observable, or adds another observer (notification function) to an existing observable

func Set

func Set[T any](name string, value T) error

Set notifies all observers that the value of an observable has changed by calling all registered notification functions

Types

This section is empty.

Jump to

Keyboard shortcuts

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