Exit
Functions
- init(opts)
Initializes the Exit parameters
- add(callback, [eventType])
Adds a callback to the exit hooks. These will be called to allow graceful clean up of resources in an asynchronous way.
- remove(callback)
Removes a callback from the hooks
- callbacks([eventType], all)
Returns a new array containing the callbacks
- onUnhandledRejection()
A shortcut for add( callback, 'unhandledRejection' )
- onUncaughtException()
A shortcut for add( callback, 'uncaughtException' )
- setExitTimeout()
Sets the max time in milliseconds to wait before an exit is forced
- getExitTimeout()
Returns the max time in milliseconds to wait before an exit is forced
- setExitDelay()
Sets the time in milliseconds to delay after hooks have finsihed before calling exit
- getExitDelay()
Gets the time in milliseconds to delay after hooks have finsihed before calling exit
- setExit()
Sets the exit function. For testing purposes.
- getExit()
Gets the exit function
- setExitCancelled()
Sets the exit cancelled function. For testing purposes. Invoked when an event has been filtered
- getExitCancelled()
Gets the exit cancelled function
- unhandle(eventType)
Removes listeners from handling the event of the given type
- handle(eventType, exitCode, opts)
Causes Exit to exit when the event type is received.
- handleErr(eventType, exitCode, opts)
Causes Exit to exit when the event type is received. It is treated as an error.
- handlers() ⇒
object
Returns the installed handlers
- addFilter(eventType, filter)
Add a filter for the given event type. A filter can be installed to stop an exit from occuring. Filters are run before and shutdown hooks.
- removeFilter(eventType, exitCode) ⇒
boolean
Causes Exit to exit when the event type is received.
- filters(eventType) ⇒
object
|array
Returns the current filters
- exit(code)
Request a graceful exit
- installDefaultHandlers()
Installs default signal handlers for SIGINT, SIGHUP, SIGTERM and SIGBREAK. This will also install uncaughtException and unhandledRejection exceptions
init(opts)
Initializes the Exit parameters
Kind: global function
Param | Type | Description |
---|---|---|
opts | object | options to set |
opts.timeout | int | (20000) sets the time in ms to exit event if callbacks havent completed |
opts.exitDelay | int | (100) sets the time in ms to delay after callbacks have completed before calling exit |
opts.exit | function | if set, this will be called instead of process.exit(). For testing |
opts.exitCancelled | function | if set, this will be called when a filter cancels an exit. For testing |
add(callback, [eventType])
Adds a callback to the exit hooks. These will be called to allow graceful clean up of resources in an asynchronous way.
Kind: global function
Param | Type | Description |
---|---|---|
callback | function | this function( err, { eventType, code } ) should return a Promise. |
[eventType] | string | the type to trigger. if this undefined/null, the callback will be triggered for all types. This is mainly used to register callbacks against 'uncaughtException' or 'unhandledRejection' |
remove(callback)
Removes a callback from the hooks
Kind: global function
Param | Type | Description |
---|---|---|
callback | function | the function to remove |
callbacks([eventType], all)
Returns a new array containing the callbacks
Kind: global function
Param | Type | Description |
---|---|---|
[eventType] | string | if supplied, this will return only the callbacks specifically registered for the eventType. |
all | boolean | if true, then both the specific and general call backs are returned |
onUnhandledRejection()
A shortcut for add( callback, 'unhandledRejection' )
onUncaughtException()
A shortcut for add( callback, 'uncaughtException' )
setExitTimeout()
Sets the max time in milliseconds to wait before an exit is forced
getExitTimeout()
Returns the max time in milliseconds to wait before an exit is forced
setExitDelay()
Sets the time in milliseconds to delay after hooks have finsihed before calling exit
getExitDelay()
Gets the time in milliseconds to delay after hooks have finsihed before calling exit
setExit()
Sets the exit function. For testing purposes.
getExit()
Gets the exit function
setExitCancelled()
Sets the exit cancelled function. For testing purposes. Invoked when an event has been filtered
getExitCancelled()
Gets the exit cancelled function
unhandle(eventType)
Removes listeners from handling the event of the given type
Kind: global function
Param | Type | Description |
---|---|---|
eventType | string | the event type to stop listening to. |
handle(eventType, exitCode, opts)
Causes Exit to exit when the event type is received.
Kind: global function
Param | Type | Description |
---|---|---|
eventType | string | the type of event to listen for |
exitCode | int | the exit code |
opts | object |
handleErr(eventType, exitCode, opts)
Causes Exit to exit when the event type is received. It is treated as an error.
Kind: global function
Param | Type | Description |
---|---|---|
eventType | string | the type of event to listen for |
exitCode | int | the exit code |
opts | object |
object
handlers() ⇒ Returns the installed handlers
Kind: global function
Returns: object
- the installed handlers
addFilter(eventType, filter)
Add a filter for the given event type. A filter can be installed to stop an exit from occuring. Filters are run before and shutdown hooks.
Kind: global function
Param | Type | Description |
---|---|---|
eventType | string | the type to filter |
filter | function | this function will be given the arguments of the event. If it returns true, the exit will not occur |
boolean
removeFilter(eventType, exitCode) ⇒ Causes Exit to exit when the event type is received.
Kind: global function
Returns: boolean
- true if the filter was removed
Param | Type | Description |
---|---|---|
eventType | string | the type of event to listen for |
exitCode | int | the exit code |
object
| array
filters(eventType) ⇒ Returns the current filters
Kind: global function
Returns: object
| array
- if eventType is null, an object of eventType : Array
Param | Type | Description |
---|---|---|
eventType | string | the type of filters. If null, all will be returned |
exit(code)
Request a graceful exit
Kind: global function
Param | Type | Description |
---|---|---|
code | int | the exit code to use, defaults to zero. |
installDefaultHandlers()
Installs default signal handlers for SIGINT, SIGHUP, SIGTERM and SIGBREAK. This will also install uncaughtException and unhandledRejection exceptions
Kind: global function