Feature contract
The phases, context, scheduling fields, and cleanup behavior.
A feature is either a function or a definition object. A function runs once at ClientReady. Objects let you choose a phase or schedule repeated work.
type Feature = FeatureFunction | OneTimeFeature | RecurringFeature;
type FeatureFunction = (context: FeatureContext) =>
void | FeatureCleanup | Promise<void | FeatureCleanup>;FeatureContext contains client, instance, and an AbortSignal named signal. The signal is aborted when features stop or startup rolls back. A one-time feature may return a cleanup function; a recurring feature may not.
| Object field | Meaning |
|---|---|
name | Optional unique name; defaults to relative file path |
phase | BeforeCommands, AfterCommands, or ClientReady |
run | Work to execute |
everyMs | Positive repeat interval, at most 2,147,483,647 ms |
runOnStart | For recurring features, run immediately instead of waiting one interval |
Phases are values of the exported FeaturePhase enum. Without phase, both one-time and recurring objects use ClientReady. One-time features are awaited before their phase finishes. An immediate recurring run starts without holding up the phase. Failure of a one-time feature rejects startup; a recurring failure is reported and the schedule continues.
Call startFeatures() after login to run client-ready work, and stopFeatures() during shutdown. Cleanup runs in reverse order. See Features for runnable examples.