lifecycle

package
v1.75.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
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

type Callback[P runtimePackage] func(ctx context.Context, event int, pkg P)

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

func (s *Store[P]) Delete(name string) bool

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

func (s *Store[P]) GetPackage(name string) P

GetPackage returns the loaded runtime package, or nil if the package doesn't exist or hasn't been loaded yet.

func (*Store[P]) HandleEvent

func (s *Store[P]) HandleEvent(event int, name string, f Callback[P])

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

func (s *Store[P]) SetPackage(name string, pkg P)

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

func (s *Store[P]) Update(name, version, settings string, f Callback[P])

Update registers a new package or detects changes to an existing one.

Change detection (evaluated in order, first match wins):

  1. Package not in store → new entry, EventVersionChanged
  2. Version differs → EventVersionChanged (cancels all in-flight tasks)
  3. Settings checksum differs → EventSettingsChanged (cancels previous settings apply)
  4. No change → callback is not invoked

For EventVersionChanged, app is nil on first install or the previously loaded app on upgrade.

Jump to

Keyboard shortcuts

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