@@ -8,6 +8,7 @@ import { type ContextState, LifecycleManager } from './lifecycle';
88import { PluginRegistry , type PluginRegistryOptions } from './plugins' ;
99import { ServiceRegistry , type ServiceResolutionScope } from './services' ;
1010import { type SubsystemDefinition , SubsystemRegistry } from './subsystems' ;
11+ import { TimerRegistry } from './timers' ;
1112
1213export type { ContextState } from './lifecycle' ;
1314export type { SubsystemCleanupResult , SubsystemDefinition , SubsystemHooks } from './subsystems' ;
@@ -18,6 +19,8 @@ export interface KernelContext<C extends object, ForkOptions> {
1819 readonly state : ContextState ;
1920 readonly logger : Logger ;
2021 readonly logBus : LogEmitter ;
22+ timeout ( delayMs : number , callback : ( ) => void | Promise < void > ) : NodeJS . Timeout ;
23+ interval ( intervalMs : number , callback : ( ) => void | Promise < void > ) : NodeJS . Timeout ;
2124
2225 install < T extends ParameterList > ( plugin : PluginDefinition < C , T > , ...args : T ) : void ;
2326
@@ -169,6 +172,7 @@ export class ContextBuilder<RootOptions, ForkOptions, Subsystems = never, Builti
169172 private readonly services : ServiceRegistry < Context > ;
170173 private readonly serviceScope : ServiceResolutionScope < Context > ;
171174 private readonly subsystems = new SubsystemRegistry ( ) ;
175+ private readonly timers : TimerRegistry ;
172176 private readonly systems : Subsystems ;
173177 private readonly plugins : PluginRegistry < Context > ;
174178 private readonly lifecycle : LifecycleManager < Context > ;
@@ -191,6 +195,11 @@ export class ContextBuilder<RootOptions, ForkOptions, Subsystems = never, Builti
191195 this . services = new ServiceRegistry ( parent ?. services ) ;
192196
193197 const getState = ( ) => this . lifecycle . state ;
198+ this . timers = this . subsystems . register ( {
199+ name : 'timers' ,
200+ create : ( ) => new TimerRegistry ( name , this . logger , getState ) ,
201+ suspend : ( timers ) => timers . clear ( ) ,
202+ } ) ;
194203 this . systems = createSubsystems ( {
195204 name,
196205 path : this . path ,
@@ -248,6 +257,14 @@ export class ContextBuilder<RootOptions, ForkOptions, Subsystems = never, Builti
248257 return this . lifecycle . state ;
249258 }
250259
260+ timeout ( delayMs : number , callback : ( ) => void | Promise < void > ) : NodeJS . Timeout {
261+ return this . timers . timeout ( delayMs , callback ) ;
262+ }
263+
264+ interval ( intervalMs : number , callback : ( ) => void | Promise < void > ) : NodeJS . Timeout {
265+ return this . timers . interval ( intervalMs , callback ) ;
266+ }
267+
251268 install < T extends ParameterList > ( plugin : PluginDefinition < Context , T > , ...args : T ) : void {
252269 this . plugins . install ( plugin , ...args ) ;
253270 }
0 commit comments