reactive

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Sentinel error to tell the rerunner to not dump the current
	// computation cache and let the error'd function retry.
	RetrySentinelError = errors.New("retry")

	// WriteThenReadDelay is how long to wait after hearing a change
	// was made, before reading that change by rerunning.
	WriteThenReadDelay = 200 * time.Millisecond
)

Functions

func AddDependency

func AddDependency(ctx context.Context, r *Resource, dep Dependency)

func Cache

func Cache(ctx context.Context, key interface{}, f ComputeFunc) (interface{}, error)

func HasRerunner

func HasRerunner(ctx context.Context) bool

func PurgeCache

func PurgeCache(ctx context.Context)

PurgeCache is meant to be use as a transition off of using the reactive cache. It allows slowly removing caching whenever the user wants, ideally between cache execution runs.

func WithDependencyCallback

func WithDependencyCallback(ctx context.Context, f DependencyCallbackFunc) context.Context

WithDependencyCallback registers a callback that is invoked when AddDependency is called with non-nil serializable dependency.

func WithDependencySetForSelection

func WithDependencySetForSelection(ctx context.Context) context.Context

Types

type ComputeFunc

type ComputeFunc func(context.Context) (interface{}, error)

type Dependency

type Dependency interface{}

func Dependencies

func Dependencies(ctx context.Context) []Dependency

func DependenciesForSelection

func DependenciesForSelection(ctx context.Context) []Dependency

type DependencyCallbackFunc

type DependencyCallbackFunc func(context.Context, Dependency)

type Rerunner

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

Rerunner automatically reruns a computation whenever its dependencies change.

The computation stops when it returns an error or after calling Stop. There is no way to get the output value from a computation. Instead, the computation should communicate its result before returning.

func NewRerunner

func NewRerunner(ctx context.Context, f ComputeFunc, minRerunInterval time.Duration, alwaysSpawnGoroutine bool) *Rerunner

NewRerunner runs f continuously

func (*Rerunner) RerunImmediately

func (r *Rerunner) RerunImmediately()

RerunImmediately removes the delay from the next recomputation.

func (*Rerunner) Stop

func (r *Rerunner) Stop()

type Resource

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

Resource represents a leaf-level dependency in a computation

func NewResource

func NewResource() *Resource

NewResource creates a new Resource

func (*Resource) Cleanup

func (r *Resource) Cleanup(f func())

Cleanup registers a handler to be called when all computations using r stop

NOTE: For f to be called, at least one computation must AddDependency r!

func (*Resource) Invalidate

func (r *Resource) Invalidate()

Invalidate permanently invalidates r

func (*Resource) Invalidated

func (n *Resource) Invalidated() bool

Invalidated returns if the node has been invalidated

func (*Resource) Strobe

func (r *Resource) Strobe()

Store invalidates all computations currently depending on r

Jump to

Keyboard shortcuts

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