Convert backend code to ES modules

Bundling code now with Rollup for its flat bundling and tree shaking
support. Front end code still goes through Webpack for browser support.
This commit is contained in:
Zaid Abdulla committed 2019-02-04 23:47:54 -08:00
1 parent 824639976f
commit 1e41c72d60
62 files changed
+718 -898

No files matched your search

+7 -8
View File
@@ -18,8 +18,9 @@
*/
"use strict";
const cluster = require("cluster");
const logger = require("./logger");
import cluster from "cluster";
import { cpus } from "os";
import * as logger from "./logger";
let respawnTimestamp = 0;
let tooManyCrashesTimestamp = 0;
@@ -62,7 +63,7 @@ function restartWorker(worker, code, signal) {
}, respawnTimestamp - now);
}
function start(workerCount, servicePort, serviceAddress) {
export function start(workerCount, servicePort, serviceAddress) {
cluster.on("listening", (worker, address) => {
if (
(address.addressType === 4 || address.addressType === 6) &&
@@ -80,16 +81,14 @@ function start(workerCount, servicePort, serviceAddress) {
cluster.on("exit", restartWorker);
if (!workerCount) workerCount = Math.max(2, require("os").cpus().length);
if (!workerCount) workerCount = Math.max(2, cpus().length);
for (let i = 0; i < workerCount; ++i) cluster.fork();
}
function stop() {
export function stop() {
cluster.removeListener("exit", restartWorker);
for (const pid in cluster.workers) cluster.workers[pid].kill();
}
exports.start = start;
exports.stop = stop;
exports.worker = cluster.worker;
export const worker = cluster.worker;