compute

package
v0.0.318 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Configurable globally only for now.
	CachingEnabled = true
	// If enabled, does not use cached contents, but still verifies that if we do have
	// cached contents, they match what we produced.
	VerifyCaching = false
)
View Source
var ErrDoneSinking = errors.New("done sinking")

ErrDoneSinking is used as a return value from Updated to indicate that no more action will be taken and Sink() should return. It is not returned as an error by any function.

View Source
var ExplainIndentValues = false

Functions

func AttachOrch

func AttachOrch(parent context.Context, orch *Orch) context.Context

func Cache

func Cache(ctx context.Context) cache.Cache

func Continuously

func Continuously(baseCtx context.Context, sinkable Sinkable, transformErr TransformErrorFunc) error

Continuously computes `sinkable` and recomputes it on any tansitive change to `sinkable`'s inputs.

`transformErr` (if not nil) allows to transform (e.g. ignore) encountered errors.

func Do

func Do(parent context.Context, do func(context.Context) error) error

func DoWithCache added in v0.0.92

func DoWithCache(parent context.Context, cache cache.Cache, do func(context.Context) error) error

func Explain

func Explain(ctx context.Context, w io.Writer, c UntypedComputable) error

func GetValue

func GetValue[V any](ctx context.Context, c Computable[V]) (V, error)

func IsPrecomputed

func IsPrecomputed[V any](c Computable[V]) (V, bool)

func MustGetDepValue

func MustGetDepValue[V any](deps Resolved, c Computable[V], key string) V

func RegisterBytesCacheable

func RegisterBytesCacheable()

func RegisterCacheable

func RegisterCacheable[V any](c Cacheable[V])

func RegisterProtoCacheable

func RegisterProtoCacheable()

func SpawnCancelableOnContinuously

func SpawnCancelableOnContinuously(ctx context.Context, f func(context.Context) error) func()

func Stop

func Stop(ctx context.Context, err error)

func Unwrap

func Unwrap(c any) (any, bool)

func WithGraphLifecycle

func WithGraphLifecycle[V any](ctx context.Context, f func(context.Context) (V, error)) (V, error)

Types

type ByteStreamWriter

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

func NewByteStream

func NewByteStream(ctx context.Context) (*ByteStreamWriter, error)

func (*ByteStreamWriter) Close

func (bsw *ByteStreamWriter) Close() error

func (*ByteStreamWriter) Complete

func (bsw *ByteStreamWriter) Complete() (bytestream.ByteStream, error)

func (*ByteStreamWriter) Write

func (bsw *ByteStreamWriter) Write(p []byte) (int, error)

type Cacheable

type Cacheable[V any] interface {
	Digester
	LoadCached(context.Context, cache.Cache, CacheableInstance, schema.Digest) (Result[V], error)
	Cache(context.Context, cache.Cache, V) (schema.Digest, error)
}

type CacheableInstance

type CacheableInstance interface {
	NewInstance() interface{}
}

type Computable

type Computable[V any] interface {
	Action() *tasks.ActionEvent
	Inputs() *In
	Output() Output // Optional.
	Compute(context.Context, Resolved) (V, error)

	UntypedComputable
}

A computable represents a node in a computation graph. Each computation node produces a value, which is computed by its `Compute` method. A node's output can be cached, and is keyed by all declared inputs. For correctness, it is required that all meaningful inputs that may impact the semantics of the output (and its digest), be listed in `Inputs`. A node can also depend on other nodes, and use their computed values. That relationship is established by declaring another Computable as an Input to this one. The resulting value, will then be available in `Resolved`. If any of node's dependencies fails to compute, the node implicitly fails as well (with the same error).

func Collect

func Collect[V any](ev *tasks.ActionEvent, computables ...Computable[V]) Computable[[]ResultWithTimestamp[V]]

func Consume

func Consume[V any](action *tasks.ActionEvent, from Computable[V], compute func(context.Context, ResultWithTimestamp[V]) error) Computable[V]

Consume ensures that the specified method is called on the value when it is computed, and before other computables that depend on the return value of Consume.

func Error

func Error[V any](err error) Computable[V]

func Inline added in v0.0.109

func Inline[To any](action *tasks.ActionEvent, compute func(context.Context) (To, error)) Computable[To]

func Map

func Map[V any](action *tasks.ActionEvent, inputs *In, output Output,
	compute func(context.Context, Resolved) (V, error)) Computable[V]

func Merge added in v0.0.117

func Merge[V any](desc string, c Computable[[]ResultWithTimestamp[[]V]]) Computable[[]V]

func Named

func Named[V any](action *tasks.ActionEvent, c Computable[V]) Computable[V]

func Precomputed

func Precomputed[V any](v V, computeDigest func(context.Context, V) (schema.Digest, error)) Computable[V]

func Sticky

func Sticky[V any](action *tasks.ActionEvent, c Computable[V]) Computable[V]

func Transform

func Transform[From, To any](desc string, from Computable[From], compute func(context.Context, From) (To, error)) Computable[To]

type ComputeDigestFunc

type ComputeDigestFunc func(context.Context, any) (schema.Digest, error)

type Detach

type Detach struct {
	Action *tasks.ActionEvent
	Do     func(context.Context) error
}

type DigestFunc

type DigestFunc func(context.Context) (schema.Digest, error)

func (DigestFunc) ComputeDigest

func (f DigestFunc) ComputeDigest(ctx context.Context) (schema.Digest, error)

type Digester

type Digester interface {
	ComputeDigest(context.Context, any) (schema.Digest, error)
}

type Digestible

type Digestible interface {
	ComputeDigest(context.Context) (schema.Digest, error)
}

type DoScoped

type DoScoped[V any] struct{}

A Computable whose lifecycle is bound to the surrounding Do() invocation. If the Computable is attempted to be computed outside a Do()-bound context, the program panics. A Do()-scoped Computable _must_ have deterministic inputs, so that a key can be calculated. This type of Computable is useful when different parts of the program want to share a computation that depends strictly on the inputs.

func (DoScoped[V]) Output

func (c DoScoped[V]) Output() Output

type Future

type Future[V any] struct {
	// contains filtered or unexported fields
}

func (*Future[V]) Wait

func (f *Future[V]) Wait(ctx context.Context) (ResultWithTimestamp[V], error)

type In

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

func Inputs

func Inputs() *In

func (*In) Bool

func (in *In) Bool(key string, v bool) *In

func (*In) Computable

func (in *In) Computable(key string, c UntypedComputable) *In

func (*In) Digest

func (in *In) Digest(key string, d Digestible) *In

func (*In) Indigestible

func (in *In) Indigestible(key string, value interface{}) *In

An unusable input (marking the corresponding Computable having non-computable inputs). We accept a variable to help with code search; but it is otherwise unused.

func (*In) JSON

func (in *In) JSON(key string, json interface{}) *In

func (*In) Marshal

func (in *In) Marshal(key string, marshaller func(context.Context, io.Writer) error) *In

func (*In) NonCacheable added in v0.0.109

func (in *In) NonCacheable() *In

func (*In) Proto

func (in *In) Proto(key string, msg proto.Message) *In

func (*In) Str

func (in *In) Str(key string, str string) *In

func (*In) StrMap

func (in *In) StrMap(key string, m map[string]string) *In

func (*In) Stringer

func (in *In) Stringer(key string, str fmt.Stringer) *In

func (*In) Strs

func (in *In) Strs(key string, strs []string) *In

type LocalScoped

type LocalScoped[V any] struct {
	// contains filtered or unexported fields
}

A Computable whose lifecycle is bound to the environment where it is computed. This is the most common option, as it yields for the clearest cancellation semantics and instance-level sharing as expected in Go. A "LocalScoped" Computable embeds a Promise which keeps track of the computation state of the Computable.

func (*LocalScoped[V]) Output

func (c *LocalScoped[V]) Output() Output

type ObserveNote added in v0.0.109

type ObserveNote string
const (
	ObserveContinuing ObserveNote = "observe.continuing"
	ObserveDone       ObserveNote = "observe.done"
)

type Orch

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

func On

func On(ctx context.Context) *Orch

func (*Orch) BestEffort added in v0.0.164

func (g *Orch) BestEffort(ev *tasks.ActionEvent, do func(context.Context) error)

func (*Orch) Call

func (g *Orch) Call(callback func(context.Context) error) error

func (*Orch) Cleanup

func (g *Orch) Cleanup(ev *tasks.ActionEvent, f func(context.Context) error)

func (*Orch) Detach

func (g *Orch) Detach(ev *tasks.ActionEvent, f func(context.Context) error)

func (*Orch) DetachWith

func (g *Orch) DetachWith(d Detach)

type Output

type Output struct {
	NonDeterministic bool
	NotCacheable     bool
}

func (Output) CanCache

func (o Output) CanCache() bool

func (Output) DontCache

func (o Output) DontCache() Output

type PrecomputeScoped

type PrecomputeScoped[V any] struct{}

This Computable embeds a "precomputed" value and Compute() is guaranteed to return immediately.

func (PrecomputeScoped[V]) Output

func (c PrecomputeScoped[V]) Output() Output

type Promise

type Promise[V any] struct {
	// contains filtered or unexported fields
}

func ErrPromise

func ErrPromise[V any](err error) *Promise[V]

func NewPromise

func NewPromise[V any](g *Orch, action *tasks.ActionEvent, callback func(context.Context) (ResultWithTimestamp[V], error)) *Promise[V]

func (*Promise[V]) Future

func (f *Promise[V]) Future() *Future[V]

type Resolved

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

type Result

type Result[V any] struct {
	Digest           schema.Digest
	NonDeterministic bool
	Value            V
}

func NoResult

func NoResult[V any]() (Result[V], error)

func (Result[V]) HasDigest

func (r Result[V]) HasDigest() bool

type ResultWithTimestamp

type ResultWithTimestamp[V any] struct {
	Result[V]
	Set       bool
	Cached    bool
	ActionID  tasks.ActionID
	Started   time.Time
	Completed time.Time // When this value was computed (if known).
	// contains filtered or unexported fields
}

func Get

func Get[V any](ctx context.Context, c Computable[V]) (ResultWithTimestamp[V], error)

func GetDep

func GetDep[V any](deps Resolved, c Computable[V], key string) (ResultWithTimestamp[V], bool)

func GetDepWithType

func GetDepWithType[V any](deps Resolved, key string) (ResultWithTimestamp[V], bool)

type Sinkable

type Sinkable interface {
	Inputs() *In
	Updated(context.Context, Resolved) error
	Cleanup(context.Context) error
}

type TransformErrorFunc

type TransformErrorFunc func(error) error

type UntypedComputable added in v0.0.109

type UntypedComputable interface {
	Action() *tasks.ActionEvent
	Inputs() *In
	Output() Output // Optional.
	// contains filtered or unexported methods
}

type Versioned

type Versioned interface {
	Observe(context.Context, func(ResultWithTimestamp[any], ObserveNote)) (func(), error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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