js-service
v1.0.1
Published
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
Downloads
5
Readme
Table of Contents
Service
Extends EventEmitter
An object with an operational state, plus #start() and #stop() lifecycle methods to transition between states. Example services include webservers, RPC servers and timers.
Parameters
name
string
failureReason
Returns the Error that caused this service to fail.
Type: Error?
state
Returns the lifecycle state of the service.
Returns State
isRunning
Returns {@code true} if this service is {@linkplain State#Running Running}.
Returns boolean
running
Returns a Promise that resolves when the service enters the 'Running' state.
Returns Promise<void>
terminated
Returns a Promise that is satisfied when the service enters the a terminal state ('Terminated' or 'Failed')
If the service enters 'Failed', the returned promise rejects with the failure reason
Returns Promise<void>
start
If the service state is State#New, this initiates service startup and returns immediately. A stopped service may not be restarted.
- Throws any Error if the service is not State#New
stop
If the service is {@linkplain State#Starting Starting} or {@linkplain State#Running Running}, this initiates service shutdown and returns immediately. If the service is {@linkplain State#New New}, it is {@linkplain State#Terminated Terminated} without having been started nor stopped. If the service has already been stopped, this method returns immediately without taking action.
doStart
This method is called by #start to initiate service startup.
This method returns Promise which should resolve when the service is operational or reject with the reason of failure.
It is invoked exactly once on service startup, even when #start is called multiple times.
doStop
This method should be used to initiate service shutdown.
This method returns Promise which should resolve when the service is has shut down or reject with the reason of failure.
doCancel
This method should be used to cancel service startup if #stop() is called before the service has transitioned to #Running
This method returns Promise which should resolve when the service is has shut down or reject with the reason of failure.
resolve
A method to resolve the associated Promise with the value passed. If the promise is already settled it does nothing.
Type: function (any): void
Parameters
value
any : This value is used to resolve the promise If the value is a Promise then the associated promise assumes the state of Promise passed as value.
reject
A method to reject the associated Promise with the value passed. If the promise is already settled it does nothing.
Type: function (any): void
Parameters
reason
any : The reason for the rejection of the Promise. Generally its an Error object. If however a Promise is passed, then the Promise itself will be the reason for rejection no matter the state of the Promise.
promise
A newly created Promise object. Initially in pending state.
Type: Promise