Documentation ¶
Index ¶
- Variables
- func AttachOrch(parent context.Context, orch *Orch) context.Context
- func Cache(ctx context.Context) cache.Cache
- func Continuously(baseCtx context.Context, sinkable Sinkable, transformErr TransformErrorFunc) error
- func Do(parent context.Context, do func(context.Context) error) error
- func DoWithCache(parent context.Context, cache cache.Cache, do func(context.Context) error) error
- func Explain(ctx context.Context, w io.Writer, c UntypedComputable) error
- func GetValue[V any](ctx context.Context, c Computable[V]) (V, error)
- func IsPrecomputed[V any](c Computable[V]) (V, bool)
- func MustGetDepValue[V any](deps Resolved, c Computable[V], key string) V
- func RegisterBytesCacheable()
- func RegisterCacheable[V any](c Cacheable[V])
- func RegisterProtoCacheable()
- func SpawnCancelableOnContinuously(ctx context.Context, f func(context.Context) error) func()
- func Stop(ctx context.Context, err error)
- func Unwrap(c any) (any, bool)
- func WithGraphLifecycle[V any](ctx context.Context, f func(context.Context) (V, error)) (V, error)
- type ByteStreamWriter
- type Cacheable
- type CacheableInstance
- type Computable
- func Collect[V any](ev *tasks.ActionEvent, computables ...Computable[V]) Computable[[]ResultWithTimestamp[V]]
- func Consume[V any](action *tasks.ActionEvent, from Computable[V], ...) Computable[V]
- func Error[V any](err error) Computable[V]
- func Inline[To any](action *tasks.ActionEvent, compute func(context.Context) (To, error)) Computable[To]
- func Map[V any](action *tasks.ActionEvent, inputs *In, output Output, ...) Computable[V]
- func Merge[V any](desc string, c Computable[[]ResultWithTimestamp[[]V]]) Computable[[]V]
- func Named[V any](action *tasks.ActionEvent, c Computable[V]) Computable[V]
- func Precomputed[V any](v V, computeDigest func(context.Context, V) (schema.Digest, error)) Computable[V]
- func Sticky[V any](action *tasks.ActionEvent, c Computable[V]) Computable[V]
- func Transform[From, To any](desc string, from Computable[From], ...) Computable[To]
- type ComputeDigestFunc
- type Detach
- type DigestFunc
- type Digester
- type Digestible
- type DoScoped
- type Future
- type In
- func (in *In) Bool(key string, v bool) *In
- func (in *In) Computable(key string, c UntypedComputable) *In
- func (in *In) Digest(key string, d Digestible) *In
- func (in *In) Indigestible(key string, value interface{}) *In
- func (in *In) JSON(key string, json interface{}) *In
- func (in *In) Marshal(key string, marshaller func(context.Context, io.Writer) error) *In
- func (in *In) NonCacheable() *In
- func (in *In) Proto(key string, msg proto.Message) *In
- func (in *In) Str(key string, str string) *In
- func (in *In) StrMap(key string, m map[string]string) *In
- func (in *In) Stringer(key string, str fmt.Stringer) *In
- func (in *In) Strs(key string, strs []string) *In
- type LocalScoped
- type ObserveNote
- type Orch
- func (g *Orch) BestEffort(ev *tasks.ActionEvent, do func(context.Context) error)
- func (g *Orch) Call(callback func(context.Context) error) error
- func (g *Orch) Cleanup(ev *tasks.ActionEvent, f func(context.Context) error)
- func (g *Orch) Detach(ev *tasks.ActionEvent, f func(context.Context) error)
- func (g *Orch) DetachWith(d Detach)
- type Output
- type PrecomputeScoped
- type Promise
- type Resolved
- type Result
- type ResultWithTimestamp
- type Sinkable
- type TransformErrorFunc
- type UntypedComputable
- type Versioned
Constants ¶
This section is empty.
Variables ¶
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 )
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.
var ExplainIndentValues = false
Functions ¶
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 DoWithCache ¶ added in v0.0.92
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 RegisterProtoCacheable ¶
func RegisterProtoCacheable()
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)
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 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 DigestFunc ¶
func (DigestFunc) ComputeDigest ¶
type Digestible ¶
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.
type In ¶
type In struct {
// contains filtered or unexported fields
}
func (*In) Computable ¶
func (in *In) Computable(key string, c UntypedComputable) *In
func (*In) Indigestible ¶
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) NonCacheable ¶ added in v0.0.109
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 (*Orch) BestEffort ¶ added in v0.0.164
func (*Orch) DetachWith ¶
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 NewPromise ¶
func NewPromise[V any](g *Orch, action *tasks.ActionEvent, callback func(context.Context) (ResultWithTimestamp[V], error)) *Promise[V]
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 TransformErrorFunc ¶
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)
}