-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime.js
45 lines (45 loc) · 1.16 KB
/
runtime.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = init;
const env_1 = require("./env");
function init(program) {
let env;
let timer;
function main() {
env = new env_1.Env();
return program(env);
}
const retry = async () => {
try {
await main();
}
catch (e) {
console.error(e);
}
finally {
if (!env?.isDisposed) {
env?.dispose__unsafe();
}
timer = setTimeout(retry, 1000);
}
};
console.log('Starting...');
retry();
process.on('uncaughtException', function (e) {
console.error(`[uncaughtException]`, e);
});
process.on('SIGINT', function cleanupAndTerminate() {
console.log('Stopping...');
try {
clearTimeout(timer);
if (!env?.isDisposed) {
env?.dispose__unsafe();
}
}
finally {
// Because Node.js is a joke sometimes:
// https://github.com/nodejs/node-v0.x-archive/issues/7101
process.kill(process.pid, 'SIGTERM');
}
});
}