UNPKG

2.16 kBTypeScriptView Raw
1/// <reference types="node" />
2import { EventEmitter } from 'events';
3import { Logger } from '../log/LogManager';
4export declare class LifecycleState {
5 static all: LifecycleState[];
6 static NOT_STARTED: LifecycleState;
7 static STARTING: LifecycleState;
8 static STARTED: LifecycleState;
9 static STOPPING: LifecycleState;
10 static STOPPED: LifecycleState;
11 static getStatesBefore(val: LifecycleState): LifecycleState[];
12 private value;
13 private name;
14 constructor(name: string, value: number);
15 toString(): string;
16 getName(): string;
17 getValue(): number;
18 isAfter(other: LifecycleState): boolean;
19 isAtOrAfter(other: LifecycleState): boolean;
20 isBefore(other: LifecycleState): boolean;
21 isAtOrBefore(other: LifecycleState): boolean;
22}
23export declare class LifecycleException extends Error {
24 private context;
25 constructor(message: string, context?: Object);
26 getContext(): Object;
27}
28export declare abstract class Lifecycle extends EventEmitter {
29 protected startTime: number;
30 protected name: string;
31 protected logger: Logger;
32 protected status: LifecycleState;
33 protected stopTime: number;
34 constructor(name: any, logger: any);
35 /**
36 * Initiates the lifecycle of this object.
37 * This is the method you should call before using the object
38 *
39 * @return {Promise<void>} A promise that will resolve when this object's lifecycle has started
40 */
41 lcStart(): Promise<void>;
42 lcStop(): Promise<void>;
43 setStatus(newStatus: LifecycleState, eventPayload?: Object): boolean;
44 getName(): string;
45 onState(state: LifecycleState, callback: Function): void;
46 onStateOnce(state: LifecycleState, callback: Function): void;
47 assertState(state: LifecycleState): void;
48 getLogger(): Logger;
49 copy(): Lifecycle;
50 getStatus(): LifecycleState;
51 protected setLogger(logger: any): void;
52 /**
53 *
54 * @return {Promise<void>}
55 */
56 protected abstract doStart(): Promise<void>;
57 /**
58 * Executes the actual logic necessary to stop the object
59 * @return {Promise.<void>}
60 */
61 protected abstract doStop(): Promise<void>;
62}