Documentation
¶
Overview ¶
Package runtime provides the core application lifecycle management for the Swarm framework. It handles module registration, building, startup, graceful shutdown, and signal handling.
Package runtime defines core module interfaces used by the Swarm framework. A module is a reusable, composable component that can be built and optionally started/stopped during the application lifecycle.
Package runtime contains the ModuleManager responsible for constructing, tracking, starting, and stopping modules. It supports:
- registering module factories
- building modules lazily
- starting lifecycle-aware modules
- stopping modules in reverse order
- thread-safe module access
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lifecycle ¶
type Lifecycle interface {
Module
Start(ctx context.Context) error
Stop(ctx context.Context) error
}
Lifecycle extends Module with Startup and Shutdown logic. Modules implementing this interface will participate in the app lifecycle.
type Module ¶
type Module interface {
Name() string
}
Module is the base interface for all modules. Every module must have a stable, unique name.
type ModuleFactoryFunc ¶
ModuleFactoryFunc describes a factory function used to construct modules. This is used by SwarmApp and ModuleManager to lazily create modules.
type ModuleManager ¶
type ModuleManager struct {
// contains filtered or unexported fields
}
ModuleManager manages module factories and constructed module instances. It ensures consistent and thread-safe lifecycle handling.
func NewModuleManager ¶
func NewModuleManager() *ModuleManager
NewModuleManager creates an empty module manager.
func (*ModuleManager) Build ¶
func (mm *ModuleManager) Build() error
Build constructs all missing modules from registered factories. It does NOT start them.
func (*ModuleManager) Get ¶
func (mm *ModuleManager) Get(name string) (Module, bool)
Get returns an already-built module instance by name. Returns false if the module does not exist.
func (*ModuleManager) RegisterFactory ¶
func (mm *ModuleManager) RegisterFactory(name string, factory ModuleFactoryFunc)
RegisterFactory registers a new module factory under a given name. This does NOT construct the module immediately. Panics on duplicate names or invalid input.
type SwarmApp ¶
type SwarmApp struct {
// contains filtered or unexported fields
}
SwarmApp represents the main application instance. It coordinates module registration, initialization, lifecycle management, and graceful shutdown.
func NewSwarmApp ¶
func NewSwarmApp() *SwarmApp
NewSwarmApp creates a new application with an empty module manager.
func (*SwarmApp) Build ¶
Build constructs all modules registered via factories. It does not start them.
func (*SwarmApp) GetModule ¶
GetModule returns a module instance by name. Second return value indicates whether the module exists.
func (*SwarmApp) RegisterModule ¶
func (a *SwarmApp) RegisterModule(name string, factory ModuleFactoryFunc)
RegisterModule registers a module factory under a given name. Modules will be constructed during Build() or Start().