UNPKG

2.15 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10Object.defineProperty(exports, "__esModule", { value: true });
11const events_1 = require("events");
12const Logger_1 = require("./Logger");
13class Console extends events_1.EventEmitter {
14 constructor(options, exe, args) {
15 super();
16 this.options = options;
17 this.exe = exe;
18 this.args = args;
19 this.logger = Logger_1.Logger;
20 this.shutdown = (resolve, reject, reason) => __awaiter(this, void 0, void 0, function* () {
21 this.logger.info('SHUTDOWN', `(${process.pid}::${process.exitCode}::${reason})`);
22 if (process.exitCode === 0) {
23 reject(reason);
24 }
25 resolve();
26 });
27 }
28 start() {
29 return __awaiter(this, void 0, void 0, function* () {
30 if (this.instance === undefined) {
31 this.logger.info(`starting "${this.exe}":`, ...this.args);
32 return (this.instance = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
33 process.on('uncaughtException', () => this.shutdown(resolve, reject, 'uncaught-exception'));
34 process.on('exit', () => this.shutdown(resolve, reject, 'exit'));
35 if (this.options.initializer) {
36 yield this.options.initializer(this);
37 }
38 })));
39 }
40 return this.instance;
41 });
42 }
43 stop() {
44 process.exit(0);
45 }
46}
47exports.Console = Console;
48//# sourceMappingURL=Console.js.map
\No newline at end of file