CoordinatedShutdown
Defined in: src/CoordinatedShutdown.ts:79
Lifecycle coordinator that runs registered tasks in well-known phases.
Ordinary application code calls addTask(phase, name, task); the runtime
guarantees task order across phases and bounded parallelism within a
phase. Task failures are logged and do NOT by default abort the rest of
the pipeline.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CoordinatedShutdown(
system):CoordinatedShutdown
Defined in: src/CoordinatedShutdown.ts:95
Parameters
Section titled “Parameters”system
Section titled “system”Returns
Section titled “Returns”CoordinatedShutdown
Properties
Section titled “Properties”defaultPhaseTimeoutMs
Section titled “defaultPhaseTimeoutMs”defaultPhaseTimeoutMs:
number=5_000
Defined in: src/CoordinatedShutdown.ts:93
Default per-phase timeout in ms. Can be changed globally or per-phase
via setPhaseTimeout. 5 seconds is a reasonable balance between
letting slow tasks finish and not blocking shutdown indefinitely.
Accessors
Section titled “Accessors”isComplete
Section titled “isComplete”Get Signature
Section titled “Get Signature”get isComplete():
boolean
Defined in: src/CoordinatedShutdown.ts:163
True once run() has completed (successful or not).
Returns
Section titled “Returns”boolean
isRunning
Section titled “isRunning”Get Signature
Section titled “Get Signature”get isRunning():
boolean
Defined in: src/CoordinatedShutdown.ts:161
True once run() has been kicked off.
Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”addPhase()
Section titled “addPhase()”addPhase(
def):void
Defined in: src/CoordinatedShutdown.ts:141
Add a custom phase. dependsOn tells the coordinator where in the order it sits.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
addTask()
Section titled “addTask()”addTask(
phase,name,task):void
Defined in: src/CoordinatedShutdown.ts:128
Register a task to run during the given phase. Task names must be unique within a phase.
Parameters
Section titled “Parameters”string
string
Returns
Section titled “Returns”void
installProcessHooks()
Section titled “installProcessHooks()”installProcessHooks(
signals?):void
Defined in: src/CoordinatedShutdown.ts:179
Install SIGTERM / SIGINT handlers that call run(ProcessTerminateReason).
Calling twice is harmless. Uninstall via removeProcessHooks.
Parameters
Section titled “Parameters”signals?
Section titled “signals?”Signals[] = ...
Returns
Section titled “Returns”void
removeProcessHooks()
Section titled “removeProcessHooks()”removeProcessHooks():
void
Defined in: src/CoordinatedShutdown.ts:192
Returns
Section titled “Returns”void
run(
reason?):Promise<void>
Defined in: src/CoordinatedShutdown.ts:169
Run the pipeline. Safe to call from multiple sites — subsequent calls return the same in-flight promise.
Parameters
Section titled “Parameters”reason?
Section titled “reason?”Reason = UnknownReason.instance
Returns
Section titled “Returns”Promise<void>
setPhaseTimeout()
Section titled “setPhaseTimeout()”setPhaseTimeout(
phase,timeoutMs):void
Defined in: src/CoordinatedShutdown.ts:154
Override the timeout for a phase. Uses defaultPhaseTimeoutMs by default.
Parameters
Section titled “Parameters”string
timeoutMs
Section titled “timeoutMs”number
Returns
Section titled “Returns”void