reactive

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func AddDependency

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

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)

Types

type ComputeFunc

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

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