UNPKG

2 kBPlain TextView Raw
1#!/usr/bin/env node
2
3'use strict';
4
5const BbPromise = require('bluebird');
6
7process.on('unhandledRejection', (e) => {
8 console.error('**PANIC** Something unexpected happened! Emulator may be in an inconsistent state!');
9 console.error(e);
10});
11process.noDeprecation = true;
12
13(() => BbPromise.resolve().then(() => {
14 // requiring here so that if anything went wrong,
15 // during require, it will be caught.
16 const argv = require('minimist')(process.argv.slice(2)),
17 env = require('./../lib/core/env'),
18 cli = require('./../lib/core/cli');
19
20 return env.init(argv)
21 .then(() => {
22 if (!env.silent) {
23 cli.asciiGreeting();
24 }
25 })
26 .then(() => {
27 // Forking individual modules to spread them across different cores if possible
28 // and restarting them automatically in case of a crash.
29 const fork = require('child_process').fork;
30
31 (function forkBlobModule(code, signal) {
32 const mod = fork(env.blobModulePath, process.argv);
33 mod.on('exit', forkBlobModule);
34 })();
35 (function forkQueueModule(code, signal) {
36 const mod = fork(env.queueModulePath, process.argv);
37 mod.on('exit', forkQueueModule);
38 })();
39 (function forkTableModule(code, signal) {
40 const mod = fork(env.tableModulePath, process.argv);
41 mod.on('exit', forkTableModule);
42 })();
43 });
44}).catch(e => {
45 process.exitCode = 1;
46 console.error(e);
47}))();
48
49// If this is a child process (e.g. forked by NPM through '$ npm start') we are propagating the signals from the
50// parent (i.e. NPM) to exit from this process and its child processes.
51process.on('SIGINT', () => { // e.g. STRG+C
52 process.exitCode = 1;
53 process.exit();
54});
55
56process.on('SIGTERM', () => { // e.g. end process from taskmanager
57 process.exitCode = 1;
58 process.exit();
59});
\No newline at end of file