Documentation
¶
Index ¶
- Constants
- type Callback
- type Package
- type Store
- func (s *Store[P]) Delete(name string) bool
- func (s *Store[P]) GetPackage(name string) P
- func (s *Store[P]) HandleEvent(event int, name string, f Callback[P])
- func (s *Store[P]) Range(f func(pkg P))
- func (s *Store[P]) SetPackage(name string, pkg P)
- func (s *Store[P]) Update(name, version, settings string, f Callback[P])
Constants ¶
const ( EventSettingsChanged = iota EventVersionChanged EventRemove EventSchedule EventRun )
Event types determine context cancellation behavior in newContext.
Root events (EventVersionChanged, EventRemove) cancel all existing contexts and create a new root. Child events cancel only the previous context for the same event key, enabling selective cancellation.
EventSchedule is shared by both enable and disable flows, providing mutual cancellation: enabling cancels a pending disable and vice versa.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callback ¶
Callback is invoked by Update when a version or settings change is detected. Receives the new context, the event type, and the current app (nil on first install).
type Package ¶
type Package[P runtimePackage] struct {
// contains filtered or unexported fields
}
Package holds the lifecycle state for a single runtime package: its loaded instance, version tracking, and a tree of cancellable contexts for coordinating concurrent operations.
Context hierarchy:
root (ctx/cancel) — created by EventVersionChanged or EventRemove ├── EventSettingsChanged child — cancelled on next settings change ├── EventSchedule child — cancelled on enable↔disable transition └── EventRun child — cancelled on next NELM drift re-run
type Store ¶
type Store[P runtimePackage] struct {
// contains filtered or unexported fields
}
Store is the central registry for runtime packages. It manages the full lifecycle: creation, updates, event handling, and removal.
func NewStore ¶
func NewStore[P runtimePackage]() *Store[P]
NewStore creates an empty Store ready for use.
func (*Store[P]) Delete ¶
Delete removes a package entry from the store if it is still in the removed state (version empty and pkg nil). Returns true if the entry was deleted.
Safe for concurrent use with Update: if the package has been re-created (new version set by Update), the entry is preserved.
func (*Store[P]) GetPackage ¶
GetPackage returns the loaded runtime package, or nil if the package doesn't exist or hasn't been loaded yet.
func (*Store[P]) HandleEvent ¶
HandleEvent renews the context for the given event type and invokes the callback with the new context and the loaded app.
For EventRemove: clears version and checksum before renewing context, so a subsequent Update sees the package as new (enabling re-create after remove).
No-op if the package doesn't exist or hasn't been loaded yet (pkg == nil). The callback executes under the Store lock.
func (*Store[P]) Range ¶
func (s *Store[P]) Range(f func(pkg P))
Range iterates over all loaded packages under a read lock. Skips entries where the app has not been loaded yet (pkg == nil). The callback must not call other Store methods.
func (*Store[P]) SetPackage ¶
SetPackage stores the loaded runtime package for a package. Called by the Load task after successfully building the app from its package files. No-op if the package entry doesn't exist (e.g., removed between download and load).
func (*Store[P]) Update ¶
Update registers a new package or detects changes to an existing one.
Change detection (evaluated in order, first match wins):
- Package not in store → new entry, EventVersionChanged
- Version differs → EventVersionChanged (cancels all in-flight tasks)
- Settings checksum differs → EventSettingsChanged (cancels previous settings apply)
- No change → callback is not invoked
For EventVersionChanged, app is nil on first install or the previously loaded app on upgrade.