reactive

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: MIT Imports: 5 Imported by: 28

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 InvalidateAfter

func InvalidateAfter(ctx context.Context, d time.Duration)

func InvalidateAt

func InvalidateAt(ctx context.Context, t time.Time)

func WithDependencyCallback added in v0.5.0

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.

Types

type ComputeFunc

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

type Dependency added in v0.5.0

type Dependency interface{}

func Dependencies added in v0.5.0

func Dependencies(ctx context.Context) []Dependency

type DependencyCallbackFunc added in v0.5.0

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) *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