Implemented by long-lived singletons (engines, services) that own background work
— timers, intervals, subscriptions, sockets, child processes — so a coordinated
shutdown can release them. Without this contract, SIGTERM/SIGINT handlers in
the entry point have no way to reach into singleton state to clear timers, leaving
the process unable to exit cleanly under load tests, CI runs, or graceful drains.
Implementers register themselves with ShutdownRegistry.Instance.Register(this)
(typically in their constructor) and provide a Shutdown() that releases the
resource synchronously or returns a promise. The registry calls each implementer
exactly once per ShutdownAll() invocation.
Optional human-readable identifier surfaced in shutdown logs and used for
de-duplication when Register is called repeatedly with the same instance
but no name. Falls back to the constructor name.
Methods
Shutdown
Shutdown():void|Promise<void>
Release the resource. Must be idempotent — ShutdownAll() may be invoked more
than once during a slow drain (e.g., SIGTERM followed by SIGINT). Should not
throw; failures are logged and remaining shutdowns continue.
Implemented by long-lived singletons (engines, services) that own background work — timers, intervals, subscriptions, sockets, child processes — so a coordinated shutdown can release them. Without this contract,
SIGTERM/SIGINThandlers in the entry point have no way to reach into singleton state to clear timers, leaving the process unable to exit cleanly under load tests, CI runs, or graceful drains.Implementers register themselves with
ShutdownRegistry.Instance.Register(this)(typically in their constructor) and provide aShutdown()that releases the resource synchronously or returns a promise. The registry calls each implementer exactly once perShutdownAll()invocation.