Skip to main content

@versionzero/module-manager / AppModule

Class: AppModule

Defined in: app-module.js:16

AppModule is a convenience "main" module that can be used to keep an app running until work is complete.

Hooks signals and exceptions to ensure clean shutdown, as well as triggering reinitialization on SIGHUP.

Use as-is to run until ModuleManager is signaled to stop, or subclass to provide your own implementation of the main or tick handlers.

Extends

  • EventEmitter

Properties

PropertyTypeDefault value
moduleManagerModuleManager | undefinedundefined

Accessors

hooksEnabled

Get Signature

get hooksEnabled(): boolean

Defined in: app-module.js:213

Enable or disable hooking signals and exception handlers

Returns

boolean

Methods

init()

init(): Promise<void>

Defined in: app-module.js:48

Lifecycle init hook

Returns

Promise<void>


start()

start(): Promise<void>

Defined in: app-module.js:80

AppModule manages a periodic "tick" loop.

If you subclass AppModule and override _tick(), you will get called every tickRate milliseconds.

Returns

Promise<void>


main()

main(): Promise<any>

Defined in: app-module.js:113

The default main implementation will simply wait until module manager is signaled.

This behavior works well for AppModule subclasses that use the "tick" functionality. Alternatively, subclasses can replace main with their own implementation.

Returns

Promise<any>


stop()

stop(): Promise<void>

Defined in: app-module.js:142

Lifecycle stop hook

Returns

Promise<void>


terminate()

terminate(exitCode?, error?): Promise<void>

Defined in: app-module.js:165

Lifecycle terminate hook.

The "main" module is the last to terminate, so it can set the process exit code.

Parameters

ParameterTypeDefault valueDescription
exitCode?number0-
error?Errorundefined-

Returns

Promise<void>


disableHooks()

disableHooks(): void

Defined in: app-module.js:229

Disable signal/exception hooks

Returns

void


enableHooks()

enableHooks(): void

Defined in: app-module.js:268

Enable signal/exception hooks

Returns

void