Documentation
¶
Index ¶
- Variables
- func Acquire[T any](ec *ExecContext, r *Resource[T]) (T, error)
- func DeleteTag[T any](d *ContextData, tag *Tag[T]) bool
- func ExecFlow[In, Out any](ec *ExecContext, f *Flow[In, Out], input In, opts ...ExecOption) (Out, error)
- func ExecFn[Out any](ec *ExecContext, fn func(*ExecContext) (Out, error), opts ...ExecOption) (Out, error)
- func GetOrSetTag[T any](d *ContextData, tag *Tag[T], values ...T) T
- func GetTag[T any](d *ContextData, tag *Tag[T]) (T, bool)
- func HasTag[T any](d *ContextData, tag *Tag[T]) bool
- func MustAcquire[T any](ec *ExecContext, r *Resource[T]) T
- func MustResolve[T any](scope Scope, atom *Atom[T]) T
- func Release[T any](scope Scope, atom *Atom[T]) error
- func Resolve[T any](scope Scope, atom *Atom[T]) (T, error)
- func ResolveAny(scope Scope, atom AnyAtom) (any, error)
- func ResolveAnyFrom(rc *ResolveContext, atom AnyAtom) (any, error)
- func ResolveFrom[T any](rc *ResolveContext, atom *Atom[T]) (T, error)
- func SeekTag[T any](d *ContextData, tag *Tag[T]) (T, bool)
- func SetTag[T any](d *ContextData, tag *Tag[T], value T)
- type AnyAtom
- type AnyExecTarget
- type AnyFlow
- type AnyTagged
- type Atom
- func NewAtom[T any](factory func(*ResolveContext) (T, error), opts ...AtomOption) *Atom[T]
- func NewAtomFrom[D1, T any](dep1 *Atom[D1], factory func(*ResolveContext, D1) (T, error), ...) *Atom[T]
- func NewAtomFrom2[D1, D2, T any](dep1 *Atom[D1], dep2 *Atom[D2], ...) *Atom[T]
- func NewAtomFrom3[D1, D2, D3, T any](dep1 *Atom[D1], dep2 *Atom[D2], dep3 *Atom[D3], ...) *Atom[T]
- func NewAtomUnsafe[T any](deps []Resolvable, factory any, opts ...AtomOption) *Atom[T]
- func Required[T any](tag *Tag[T]) *Atom[T]
- type AtomOption
- type AtomState
- type CircularDepError
- type ContextData
- func (d *ContextData) All() iter.Seq2[string, any]
- func (d *ContextData) Clear()
- func (d *ContextData) Delete(key string) bool
- func (d *ContextData) Get(key string) (any, bool)
- func (d *ContextData) Has(key string) bool
- func (d *ContextData) Seek(key string) (any, bool)
- func (d *ContextData) SeekAll(key string) iter.Seq[any]
- func (d *ContextData) Set(key string, value any)
- type Controller
- func (c *Controller[T]) Get() (T, error)
- func (c *Controller[T]) Invalidate()
- func (c *Controller[T]) On(event ControllerEvent, listener func()) UnsubscribeFunc
- func (c *Controller[T]) Release() error
- func (c *Controller[T]) Resolve() (T, error)
- func (c *Controller[T]) Set(value T) error
- func (c *Controller[T]) State() AtomState
- func (c *Controller[T]) Update(fn func(T) T) error
- type ControllerEvent
- type CreateContextOption
- type Disposer
- type ExecContext
- func (ec *ExecContext) Close(cause error) error
- func (ec *ExecContext) Closed() bool
- func (ec *ExecContext) Context() context.Context
- func (ec *ExecContext) Data() *ContextData
- func (ec *ExecContext) Depth() int
- func (ec *ExecContext) Input() any
- func (ec *ExecContext) Name() string
- func (ec *ExecContext) OnClose(fn func(error) error)
- func (ec *ExecContext) Parent() *ExecContext
- func (ec *ExecContext) Root() *ExecContext
- func (ec *ExecContext) Scope() Scope
- type ExecOption
- type ExecWrapper
- type Extension
- type Flow
- func NewFlow[In, Out any](factory func(*ExecContext, In) (Out, error), opts ...FlowOption) *Flow[In, Out]
- func NewFlowFrom[D1, In, Out any](dep1 FlowDep[D1], factory func(*ExecContext, In, D1) (Out, error), ...) *Flow[In, Out]
- func NewFlowFrom2[D1, D2, In, Out any](dep1 FlowDep[D1], dep2 FlowDep[D2], ...) *Flow[In, Out]
- func NewFlowFrom3[D1, D2, D3, In, Out any](dep1 FlowDep[D1], dep2 FlowDep[D2], dep3 FlowDep[D3], ...) *Flow[In, Out]
- func NewFlowUnsafe[In, Out any](deps []Resolvable, factory any, opts ...FlowOption) *Flow[In, Out]
- type FlowDep
- type FlowOption
- type GCOptions
- type Initializer
- type InvalidationLoopError
- type ParseError
- type PresetOption
- func Preset[T any](target *Atom[T], value T) PresetOption
- func PresetAtom[T any](target *Atom[T], replacement *Atom[T]) PresetOption
- func PresetFlow[In, Out any](target *Flow[In, Out], replacement *Flow[In, Out]) PresetOption
- func PresetFlowFn[In, Out any](target *Flow[In, Out], fn func(*ExecContext) (Out, error)) PresetOption
- type Resolvable
- type ResolveContext
- type ResolveWrapper
- type Resource
- func NewResource[T any](name string, factory func(*ExecContext) (T, error)) *Resource[T]
- func NewResourceFrom[D1, T any](dep1 FlowDep[D1], name string, factory func(*ExecContext, D1) (T, error)) *Resource[T]
- func NewResourceFrom2[D1, D2, T any](dep1 FlowDep[D1], dep2 FlowDep[D2], name string, ...) *Resource[T]
- type Scope
- type ScopeOption
- type SelectHandle
- type Tag
- func (t *Tag[T]) All(source []AnyTagged) iter.Seq[T]
- func (t *Tag[T]) Collect(source []AnyTagged) []T
- func (t *Tag[T]) Find(source []AnyTagged) (T, bool)
- func (t *Tag[T]) Get(source []AnyTagged) (T, error)
- func (t *Tag[T]) Key() string
- func (t *Tag[T]) Label() string
- func (t *Tag[T]) Value(v T) *Tagged[T]
- type Tagged
- type UnsubscribeFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotResolved = errors.New("flux: atom not resolved — call Resolve before accessing value") ErrClosed = errors.New("flux: exec context is closed") ErrScopeClosed = errors.New("flux: scope has been disposed") )
var NameTag = &Tag[string]{label: "name", key: "@flux/name"}
Functions ¶
func Acquire ¶
func Acquire[T any](ec *ExecContext, r *Resource[T]) (T, error)
Acquire lazily resolves a Resource within an ExecContext. On first call, runs the factory and caches the result in ec.Data(). Subsequent calls (or calls from child ExecContexts) return the cached value. Safe for concurrent use from multiple goroutines on the same ExecContext. Errors are NOT cached — a failed Acquire can be retried.
func ExecFlow ¶
func ExecFlow[In, Out any](ec *ExecContext, f *Flow[In, Out], input In, opts ...ExecOption) (Out, error)
func ExecFn ¶
func ExecFn[Out any](ec *ExecContext, fn func(*ExecContext) (Out, error), opts ...ExecOption) (Out, error)
func GetOrSetTag ¶
func GetOrSetTag[T any](d *ContextData, tag *Tag[T], values ...T) T
func MustAcquire ¶
func MustAcquire[T any](ec *ExecContext, r *Resource[T]) T
MustAcquire is like Acquire but panics on error.
func MustResolve ¶
func ResolveAnyFrom ¶
func ResolveAnyFrom(rc *ResolveContext, atom AnyAtom) (any, error)
func ResolveFrom ¶
func ResolveFrom[T any](rc *ResolveContext, atom *Atom[T]) (T, error)
func SetTag ¶
func SetTag[T any](d *ContextData, tag *Tag[T], value T)
Types ¶
type AnyAtom ¶
type AnyAtom interface {
Name() string
ID() uint64
Deps() []Resolvable
// contains filtered or unexported methods
}
type AnyExecTarget ¶
type AnyExecTarget interface {
ExecTargetName() string
}
type AnyFlow ¶
type AnyFlow interface {
Name() string
ID() uint64
Deps() []Resolvable
// contains filtered or unexported methods
}
type Atom ¶
type Atom[T any] struct { // contains filtered or unexported fields }
func NewAtom ¶
func NewAtom[T any](factory func(*ResolveContext) (T, error), opts ...AtomOption) *Atom[T]
func NewAtomFrom ¶
func NewAtomFrom[D1, T any](dep1 *Atom[D1], factory func(*ResolveContext, D1) (T, error), opts ...AtomOption) *Atom[T]
func NewAtomFrom2 ¶
func NewAtomFrom2[D1, D2, T any](dep1 *Atom[D1], dep2 *Atom[D2], factory func(*ResolveContext, D1, D2) (T, error), opts ...AtomOption) *Atom[T]
func NewAtomFrom3 ¶
func NewAtomFrom3[D1, D2, D3, T any](dep1 *Atom[D1], dep2 *Atom[D2], dep3 *Atom[D3], factory func(*ResolveContext, D1, D2, D3) (T, error), opts ...AtomOption) *Atom[T]
func NewAtomUnsafe ¶
func NewAtomUnsafe[T any](deps []Resolvable, factory any, opts ...AtomOption) *Atom[T]
func (*Atom) Deps ¶
func (a *Atom) Deps() []Resolvable
type AtomOption ¶
type AtomOption func(*atomBase)
func WithAtomName ¶
func WithAtomName(name string) AtomOption
func WithAtomTags ¶
func WithAtomTags(tags ...AnyTagged) AtomOption
func WithKeepAlive ¶
func WithKeepAlive() AtomOption
type CircularDepError ¶
type CircularDepError struct {
Path []uint64
}
func (*CircularDepError) Error ¶
func (e *CircularDepError) Error() string
type ContextData ¶
type ContextData struct {
// contains filtered or unexported fields
}
func (*ContextData) Clear ¶
func (d *ContextData) Clear()
func (*ContextData) Delete ¶
func (d *ContextData) Delete(key string) bool
func (*ContextData) Has ¶
func (d *ContextData) Has(key string) bool
func (*ContextData) Set ¶
func (d *ContextData) Set(key string, value any)
type Controller ¶
type Controller[T any] struct { // contains filtered or unexported fields }
func GetController ¶
func GetController[T any](s Scope, atom *Atom[T]) *Controller[T]
func GetControllerResolved ¶
func GetControllerResolved[T any](s Scope, atom *Atom[T]) (*Controller[T], error)
func (*Controller[T]) Get ¶
func (c *Controller[T]) Get() (T, error)
func (*Controller[T]) Invalidate ¶
func (c *Controller[T]) Invalidate()
func (*Controller[T]) On ¶
func (c *Controller[T]) On(event ControllerEvent, listener func()) UnsubscribeFunc
func (*Controller[T]) Release ¶
func (c *Controller[T]) Release() error
func (*Controller[T]) Resolve ¶
func (c *Controller[T]) Resolve() (T, error)
func (*Controller[T]) Set ¶
func (c *Controller[T]) Set(value T) error
func (*Controller[T]) State ¶
func (c *Controller[T]) State() AtomState
func (*Controller[T]) Update ¶
func (c *Controller[T]) Update(fn func(T) T) error
type ControllerEvent ¶
type ControllerEvent int
const ( EventResolving ControllerEvent = iota EventResolved EventAll )
func (ControllerEvent) String ¶
func (e ControllerEvent) String() string
type CreateContextOption ¶
type CreateContextOption func(*ecOptions)
func WithContextTags ¶
func WithContextTags(tags ...AnyTagged) CreateContextOption
type ExecContext ¶
type ExecContext struct {
// contains filtered or unexported fields
}
func (*ExecContext) Close ¶
func (ec *ExecContext) Close(cause error) error
func (*ExecContext) Closed ¶
func (ec *ExecContext) Closed() bool
func (*ExecContext) Context ¶
func (ec *ExecContext) Context() context.Context
func (*ExecContext) Data ¶
func (ec *ExecContext) Data() *ContextData
func (*ExecContext) Depth ¶
func (ec *ExecContext) Depth() int
func (*ExecContext) Input ¶
func (ec *ExecContext) Input() any
func (*ExecContext) Name ¶
func (ec *ExecContext) Name() string
func (*ExecContext) OnClose ¶
func (ec *ExecContext) OnClose(fn func(error) error)
func (*ExecContext) Parent ¶
func (ec *ExecContext) Parent() *ExecContext
func (*ExecContext) Root ¶
func (ec *ExecContext) Root() *ExecContext
func (*ExecContext) Scope ¶
func (ec *ExecContext) Scope() Scope
type ExecOption ¶
type ExecOption func(*execOpts)
func WithExecName ¶
func WithExecName(name string) ExecOption
func WithExecTags ¶
func WithExecTags(tags ...AnyTagged) ExecOption
type ExecWrapper ¶
type ExecWrapper interface {
WrapExec(next func() (any, error), target AnyExecTarget, ec *ExecContext) (any, error)
}
type Flow ¶
type Flow[In, Out any] struct { // contains filtered or unexported fields }
func NewFlow ¶
func NewFlow[In, Out any](factory func(*ExecContext, In) (Out, error), opts ...FlowOption) *Flow[In, Out]
func NewFlowFrom ¶
func NewFlowFrom[D1, In, Out any](dep1 FlowDep[D1], factory func(*ExecContext, In, D1) (Out, error), opts ...FlowOption) *Flow[In, Out]
NewFlowFrom creates a Flow with one dependency (Atom or Resource).
func NewFlowFrom2 ¶
func NewFlowFrom2[D1, D2, In, Out any](dep1 FlowDep[D1], dep2 FlowDep[D2], factory func(*ExecContext, In, D1, D2) (Out, error), opts ...FlowOption) *Flow[In, Out]
NewFlowFrom2 creates a Flow with two dependencies (Atom or Resource).
func NewFlowFrom3 ¶
func NewFlowFrom3[D1, D2, D3, In, Out any](dep1 FlowDep[D1], dep2 FlowDep[D2], dep3 FlowDep[D3], factory func(*ExecContext, In, D1, D2, D3) (Out, error), opts ...FlowOption) *Flow[In, Out]
NewFlowFrom3 creates a Flow with three dependencies (Atom or Resource).
func NewFlowUnsafe ¶
func NewFlowUnsafe[In, Out any](deps []Resolvable, factory any, opts ...FlowOption) *Flow[In, Out]
func (*Flow) Deps ¶
func (f *Flow) Deps() []Resolvable
func (*Flow[In, Out]) ExecTargetName ¶
type FlowDep ¶
type FlowDep[T any] interface { Resolvable // contains filtered or unexported methods }
FlowDep[T] is a typed dependency that can be resolved from an ExecContext. Both *Atom[T] and *Resource[T] implement this interface, so NewFlowFrom and NewFlowFrom2 accept either as a dependency.
type FlowOption ¶
type FlowOption func(*flowBase)
func WithFlowName ¶
func WithFlowName(name string) FlowOption
func WithFlowTags ¶
func WithFlowTags(tags ...AnyTagged) FlowOption
type Initializer ¶
type InvalidationLoopError ¶
type InvalidationLoopError struct {
Path []string
}
func (*InvalidationLoopError) Error ¶
func (e *InvalidationLoopError) Error() string
type ParseError ¶
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type PresetOption ¶
type PresetOption struct {
// contains filtered or unexported fields
}
func Preset ¶
func Preset[T any](target *Atom[T], value T) PresetOption
func PresetAtom ¶
func PresetAtom[T any](target *Atom[T], replacement *Atom[T]) PresetOption
func PresetFlow ¶
func PresetFlow[In, Out any](target *Flow[In, Out], replacement *Flow[In, Out]) PresetOption
func PresetFlowFn ¶
func PresetFlowFn[In, Out any](target *Flow[In, Out], fn func(*ExecContext) (Out, error)) PresetOption
type Resolvable ¶
Resolvable is anything that can appear as a named dependency. Both *Atom[T] and *Resource[T] implement this interface.
type ResolveContext ¶
type ResolveContext struct {
// contains filtered or unexported fields
}
func (*ResolveContext) Atom ¶
func (rc *ResolveContext) Atom() AnyAtom
func (*ResolveContext) Cleanup ¶
func (rc *ResolveContext) Cleanup(fn func() error)
func (*ResolveContext) Context ¶
func (rc *ResolveContext) Context() context.Context
func (*ResolveContext) Data ¶
func (rc *ResolveContext) Data() *ContextData
func (*ResolveContext) Invalidate ¶
func (rc *ResolveContext) Invalidate()
func (*ResolveContext) Scope ¶
func (rc *ResolveContext) Scope() Scope
type ResolveWrapper ¶
type Resource ¶
type Resource[T any] struct { // contains filtered or unexported fields }
Resource represents a lazily-resolved, ExecContext-scoped value. Unlike Atom (which is cached per Scope), a Resource is cached per ExecContext and inherited by child contexts via the ContextData parent chain.
func NewResource ¶
func NewResource[T any](name string, factory func(*ExecContext) (T, error)) *Resource[T]
NewResource creates a new Resource with the given name and factory function. The factory receives the ExecContext and can access scope-level atoms, register cleanup via OnClose, and chain to other resources via Acquire.
func NewResourceFrom ¶
func NewResourceFrom[D1, T any](dep1 FlowDep[D1], name string, factory func(*ExecContext, D1) (T, error)) *Resource[T]
NewResourceFrom creates a Resource with one dependency (Resource or Atom).
func NewResourceFrom2 ¶
func NewResourceFrom2[D1, D2, T any](dep1 FlowDep[D1], dep2 FlowDep[D2], name string, factory func(*ExecContext, D1, D2) (T, error)) *Resource[T]
NewResourceFrom2 creates a Resource with two dependencies (Resource or Atom).
type Scope ¶
type Scope interface {
Ready() error
ReadyErr() error
Tags() []AnyTagged
CreateContext(opts ...CreateContextOption) *ExecContext
On(state AtomState, atom AnyAtom, listener func()) UnsubscribeFunc
Flush() error
Dispose() error
}
type ScopeOption ¶
type ScopeOption func(*scopeOpts)
func WithExtensions ¶
func WithExtensions(exts ...Extension) ScopeOption
func WithGC ¶
func WithGC(opts GCOptions) ScopeOption
func WithPresets ¶
func WithPresets(presets ...PresetOption) ScopeOption
func WithScopeTags ¶
func WithScopeTags(tags ...AnyTagged) ScopeOption
type SelectHandle ¶
type SelectHandle[S any] struct { // contains filtered or unexported fields }
func Select ¶
func Select[T any, S comparable](s Scope, atom *Atom[T], selector func(T) S) *SelectHandle[S]
func SelectWith ¶
func (*SelectHandle[S]) Get ¶
func (h *SelectHandle[S]) Get() S
func (*SelectHandle[S]) Subscribe ¶
func (h *SelectHandle[S]) Subscribe(listener func()) UnsubscribeFunc
type Tag ¶
type Tag[T any] struct { // contains filtered or unexported fields }
func NewTagWithDefault ¶
func NewTagWithParse ¶
type UnsubscribeFunc ¶
type UnsubscribeFunc func()