1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| 'use strict';
|
| const assert = require('assert');
| const is = require('is-type-of');
| const once = require('once');
|
| module.exports = getExitFunction;
|
| function getExitFunction(beforeExit, logger, label) {
| if (beforeExit) assert(is.function(beforeExit), 'beforeExit only support function');
|
| return once(code => {
| if (!beforeExit) process.exit(code);
| Promise.resolve()
| .then(() => {
| return beforeExit();
| })
| .then(() => {
| logger.info('[%s] beforeExit success', label);
| process.exit(code);
| })
| .catch(err => {
| logger.error('[%s] beforeExit fail, error: %s', label, err.message);
| process.exit(code);
| });
| });
|
| }
|
|