From d5f295cb7d909fdde225382072c947bc0638fc17 Mon Sep 17 00:00:00 2001 From: Snider Date: Fri, 20 Mar 2026 18:02:07 +0000 Subject: [PATCH] =?UTF-8?q?refactor:=20AX=20naming=20=E2=80=94=20wg=20?= =?UTF-8?q?=E2=86=92=20waitgroup,=20ctx=20=E2=86=92=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Virgil --- pkg/core/contract.go | 2 +- pkg/core/core.go | 68 ++++++++++++++++++++++---------------------- pkg/core/runtime.go | 4 +-- pkg/core/task.go | 2 +- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/pkg/core/contract.go b/pkg/core/contract.go index 15ba428..ddf0def 100644 --- a/pkg/core/contract.go +++ b/pkg/core/contract.go @@ -86,7 +86,7 @@ func New(opts ...Options) *Core { services: &serviceRegistry{services: make(map[string]*Service)}, commands: &commandRegistry{commands: make(map[string]*Command)}, } - c.ctx, c.cancel = context.WithCancel(context.Background()) + c.context, c.cancel = context.WithCancel(context.Background()) if len(opts) > 0 { cp := make(Options, len(opts[0])) diff --git a/pkg/core/core.go b/pkg/core/core.go index 1ec66d0..06cb815 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -15,51 +15,51 @@ import ( // Core is the central application object that manages services, assets, and communication. type Core struct { - options *Options // c.Options() — Input configuration used to create this Core - app *App // c.App() — Application identity + optional GUI runtime - data *Data // c.Data() — Embedded/stored content from packages - drive *Drive // c.Drive() — Resource handle registry (transports) - fs *Fs // c.Fs() — Local filesystem I/O (sandboxable) - config *Config // c.Config() — Configuration, settings, feature flags - error *ErrorPanic // c.Error() — Panic recovery and crash reporting - log *ErrorLog // c.Log() — Structured logging + error wrapping - cli *Cli // c.Cli() — CLI surface layer - commands *commandRegistry // c.Command("path") — Command tree - services *serviceRegistry // c.Service("name") — Service registry - lock *Lock // c.Lock("name") — Named mutexes - ipc *Ipc // c.IPC() — Message bus for IPC - i18n *I18n // c.I18n() — Internationalisation and locale collection + options *Options // c.Options() — Input configuration used to create this Core + app *App // c.App() — Application identity + optional GUI runtime + data *Data // c.Data() — Embedded/stored content from packages + drive *Drive // c.Drive() — Resource handle registry (transports) + fs *Fs // c.Fs() — Local filesystem I/O (sandboxable) + config *Config // c.Config() — Configuration, settings, feature flags + error *ErrorPanic // c.Error() — Panic recovery and crash reporting + log *ErrorLog // c.Log() — Structured logging + error wrapping + cli *Cli // c.Cli() — CLI surface layer + commands *commandRegistry // c.Command("path") — Command tree + services *serviceRegistry // c.Service("name") — Service registry + lock *Lock // c.Lock("name") — Named mutexes + ipc *Ipc // c.IPC() — Message bus for IPC + i18n *I18n // c.I18n() — Internationalisation and locale collection - ctx context.Context + context context.Context cancel context.CancelFunc taskIDCounter atomic.Uint64 - wg sync.WaitGroup + waitgroup sync.WaitGroup shutdown atomic.Bool } // --- Accessors --- -func (c *Core) Options() *Options { return c.options } -func (c *Core) App() *App { return c.app } -func (c *Core) Data() *Data { return c.data } -func (c *Core) Drive() *Drive { return c.drive } -func (c *Core) Embed() Result { return c.data.Get("app") } // legacy — use Data() -func (c *Core) Fs() *Fs { return c.fs } -func (c *Core) Config() *Config { return c.config } -func (c *Core) Error() *ErrorPanic { return c.error } -func (c *Core) Log() *ErrorLog { return c.log } -func (c *Core) Cli() *Cli { return c.cli } -func (c *Core) IPC() *Ipc { return c.ipc } -func (c *Core) I18n() *I18n { return c.i18n } -func (c *Core) Context() context.Context { return c.ctx } -func (c *Core) Core() *Core { return c } +func (c *Core) Options() *Options { return c.options } +func (c *Core) App() *App { return c.app } +func (c *Core) Data() *Data { return c.data } +func (c *Core) Drive() *Drive { return c.drive } +func (c *Core) Embed() Result { return c.data.Get("app") } // legacy — use Data() +func (c *Core) Fs() *Fs { return c.fs } +func (c *Core) Config() *Config { return c.config } +func (c *Core) Error() *ErrorPanic { return c.error } +func (c *Core) Log() *ErrorLog { return c.log } +func (c *Core) Cli() *Cli { return c.cli } +func (c *Core) IPC() *Ipc { return c.ipc } +func (c *Core) I18n() *I18n { return c.i18n } +func (c *Core) Context() context.Context { return c.context } +func (c *Core) Core() *Core { return c } // --- IPC (uppercase aliases) --- -func (c *Core) ACTION(msg Message) Result { return c.Action(msg) } -func (c *Core) QUERY(q Query) Result { return c.Query(q) } -func (c *Core) QUERYALL(q Query) Result { return c.QueryAll(q) } -func (c *Core) PERFORM(t Task) Result { return c.Perform(t) } +func (c *Core) ACTION(msg Message) Result { return c.Action(msg) } +func (c *Core) QUERY(q Query) Result { return c.Query(q) } +func (c *Core) QUERYALL(q Query) Result { return c.QueryAll(q) } +func (c *Core) PERFORM(t Task) Result { return c.Perform(t) } // --- Error+Log --- diff --git a/pkg/core/runtime.go b/pkg/core/runtime.go index 6eae703..89c296e 100644 --- a/pkg/core/runtime.go +++ b/pkg/core/runtime.go @@ -34,7 +34,7 @@ func (r *ServiceRuntime[T]) Config() *Config { return r.core.Config() } // ServiceStartup runs OnStart for all registered services that have one. func (c *Core) ServiceStartup(ctx context.Context, options any) Result { c.shutdown.Store(false) - c.ctx, c.cancel = context.WithCancel(ctx) + c.context, c.cancel = context.WithCancel(ctx) startables := c.Startables() if startables.OK { for _, s := range startables.Value.([]*Service) { @@ -60,7 +60,7 @@ func (c *Core) ServiceShutdown(ctx context.Context) Result { // Drain background tasks before stopping services. done := make(chan struct{}) go func() { - c.wg.Wait() + c.waitgroup.Wait() close(done) }() select { diff --git a/pkg/core/task.go b/pkg/core/task.go index 386bfcd..ed4859c 100644 --- a/pkg/core/task.go +++ b/pkg/core/task.go @@ -28,7 +28,7 @@ func (c *Core) PerformAsync(t Task) Result { tid.SetTaskIdentifier(taskID) } c.ACTION(ActionTaskStarted{TaskIdentifier: taskID, Task: t}) - c.wg.Go(func() { + c.waitgroup.Go(func() { defer func() { if rec := recover(); rec != nil { err := E("core.PerformAsync", Sprint("panic: ", rec), nil)