Skip to content

Refactor @matrixai/async-init into a lifecycle kernel, keep adapters in-repo, keep js-container as the only companion repo #46

@CMCDragonkai

Description

@CMCDragonkai

@matrixai/async-init has grown beyond "async init decorators".

It is effectively a lifecycle kernel for long-running, resourceful, asynchronous service objects.

This issue is to do the v3 refactor intentionally, instead of continuing to extend the current decorator-first model.

The result should stay constrained to just 2 repos for now:

  • @matrixai/async-init - js-async-init
  • @matrixai/container - js-container

No extra package splitting yet. Any runtime-specific integrations should stay inside these repos as adapters/subpath exports.

Why

The current library is doing multiple jobs at once:

  • lifecycle state management
  • concurrent transition control
  • runtime method admission (@ready)
  • error policy
  • events/tracing hooks

It also duplicates the same core machinery across:

  • CreateDestroy
  • StartStop
  • CreateDestroyStartStop

Conceptually, this is no longer just "async init". It is a reusable lifecycle model for invisible service objects in JS runtimes.

That is useful not only in Node/CLI, but also in browser, worker, scene/runtime, transport, and WASM-adjacent code.

Goal

Refactor @matrixai/async-init into a clean lifecycle kernel that:

  • preserves the original lifecycle motivations
  • supports modern TS/ESM/runtime assumptions
  • remains usable in backend and frontend environments
  • stops treating decorators as the architectural center
  • leaves graph wiring and lazy dependency planning to js-container

Non-goals

This issue is not about:

  • turning @matrixai/async-init into a full IoC framework
  • turning it into a full actor/process runtime
  • adding many more repos/packages
  • replacing React/component lifecycle
  • rebuilding the world before landing v3

High-level direction

@matrixai/async-init

Owns:

  • lifecycle state machine
  • transition orchestration
  • operation admission
  • ownership/disposal semantics
  • lifecycle events / tracing hooks
  • compatibility decorators
  • runtime adapters in the same repo

@matrixai/container

Owns:

  • service tokens/providers
  • scopes
  • overrides
  • lazy dependency edges
  • boot/shutdown ordering

Core refactor principles

  1. Replace the 3 duplicated lifecycle implementations with 1 internal lifecycle engine.
  2. Treat CreateDestroy, StartStop, and CreateDestroyStartStop as profiles over that engine.
  3. Replace error-instance APIs with error classes/factories/options.
  4. Remove stack-reset magic as part of the breaking change.
  5. Keep decorators as compatibility sugar, not the core abstraction.
  6. Keep runtime adapters in the same repo via subpath exports.
  7. Keep js-container as the only companion repo for graph wiring.

Expected outcome

After this work, @matrixai/async-init should feel like a small, dependable substrate for invisible async services in JS, rather than a strange decorator package that happens to encode runtime semantics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions