UNPKG

derby

Version:

MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers.

36 lines (35 loc) 1.08 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.run = void 0; // import as namespace to avoid transform as cluster.default var cluster = require("node:cluster"); var isProduction = process.env.NODE_ENV === 'production'; function run(createServer) { // In production if (isProduction) return createServer(); // @ts-expect-error imported without default; need type update? if (cluster.isPrimary) { console.log('Primary PID ', process.pid); startWorker(); } else { createServer(); } } exports.run = run; function startWorker() { // @ts-expect-error imported without default; need type update? var worker = cluster.fork(); worker.once('disconnect', function () { worker.process.kill(); }); worker.on('message', function (message) { if (message.type === 'reload') { if (worker.isDead()) return; console.log('Killing %d', worker.process.pid); worker.process.kill(); startWorker(); } }); }