Class: TerminationMonitor
Prefactor TypeScript SDK / @prefactor/core / TerminationMonitor
Class: TerminationMonitor
Section titled “Class: TerminationMonitor”Defined in: packages/core/src/monitoring/termination-monitor.ts:22
Monitors a p2 agent instance for external termination.
Primary detection: the transport calls detectTermination() whenever a
span create or finish response contains a control signal. This is fast
(detected on the next span API response) and has zero overhead.
Fallback detection: slow polling at pollIntervalMs (default 30s) covers
idle agents that are not actively emitting spans.
Accessors
Section titled “Accessors”signal
Section titled “signal”Get Signature
Section titled “Get Signature”get signal():
AbortSignal
Defined in: packages/core/src/monitoring/termination-monitor.ts:94
Returns
Section titled “Returns”AbortSignal
terminated
Section titled “terminated”Get Signature
Section titled “Get Signature”get terminated():
boolean
Defined in: packages/core/src/monitoring/termination-monitor.ts:98
Returns
Section titled “Returns”boolean
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TerminationMonitor(
httpClient,getAgentInstanceId,pollIntervalMs?):TerminationMonitor
Defined in: packages/core/src/monitoring/termination-monitor.ts:37
Parameters
Section titled “Parameters”httpClient
Section titled “httpClient”getAgentInstanceId
Section titled “getAgentInstanceId”() => string | null
pollIntervalMs?
Section titled “pollIntervalMs?”number = 30_000
Returns
Section titled “Returns”TerminationMonitor
Methods
Section titled “Methods”detectTermination()
Section titled “detectTermination()”detectTermination(
reason):void
Defined in: packages/core/src/monitoring/termination-monitor.ts:47
Primary termination path — called by the transport when a span response contains a control signal. No polling latency.
Parameters
Section titled “Parameters”reason
Section titled “reason”string | null
Returns
Section titled “Returns”void
sync()
Section titled “sync()”sync():
void
Defined in: packages/core/src/monitoring/termination-monitor.ts:57
Drives the fallback poll lifecycle. Call periodically (e.g., every 1s) to start or stop polling based on whether an agent instance ID is known.
Returns
Section titled “Returns”void
onTerminated()
Section titled “onTerminated()”onTerminated(
callback): () =>void
Defined in: packages/core/src/monitoring/termination-monitor.ts:87
Parameters
Section titled “Parameters”callback
Section titled “callback”Returns
Section titled “Returns”():
void
Returns
Section titled “Returns”void
reset()
Section titled “reset()”reset():
void
Defined in: packages/core/src/monitoring/termination-monitor.ts:107
Resets the monitor for a new agent run. Clears terminated state, creates a fresh AbortSignal, and stops any in-progress fallback polling. Registered callbacks are preserved.
Returns
Section titled “Returns”void
destroy()
Section titled “destroy()”destroy():
void
Defined in: packages/core/src/monitoring/termination-monitor.ts:117
Returns
Section titled “Returns”void