Skip to content

Commit 53ae6f7

Browse files
committed
chore: commit build
1 parent d6b53b1 commit 53ae6f7

4 files changed

Lines changed: 611 additions & 2 deletions

File tree

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
dist/
2-
lib/
31
node_modules/

lib/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cluster from 'node:cluster';
2+
3+
// src/index.ts
4+
if (cluster.isPrimary) import('./main-GBVOEOJZ.js');
5+
else import('./thread-J2KA4DUN.js');

lib/main-GBVOEOJZ.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import cluster from 'node:cluster';
2+
import { availableParallelism } from 'node:os';
3+
4+
// src/main.ts
5+
process.loadEnvFile();
6+
var env = {
7+
PORT: process.env.PORT,
8+
AUTH: process.env.AUTH
9+
};
10+
var sts = /* @__PURE__ */ new Map();
11+
var player = /* @__PURE__ */ new Map();
12+
var processed = /* @__PURE__ */ new Map();
13+
function onOnline() {
14+
console.log(`Worker ${this.id} online`);
15+
}
16+
function onMessage(payload) {
17+
const map = payload.op === "player" ? player : payload.op === "processed" ? processed : sts;
18+
if (payload.value !== void 0) map.set(payload.key, payload.value);
19+
else this.send({ id: `${payload.op}:${payload.key}`, data: map.get(payload.key) ?? null });
20+
if (sts.has(payload.key) && processed.has(payload.key)) player.delete(payload.key);
21+
}
22+
function onError(err) {
23+
console.log(`Worker ${this.id} errored:`, err);
24+
}
25+
function onExit(code) {
26+
console.log(`Worker ${this.id} exited with code ${code}`);
27+
if (code !== 0) attachEvents(cluster.fork({ env }));
28+
}
29+
function attachEvents(worker) {
30+
worker.on("online", onOnline);
31+
worker.on("message", onMessage);
32+
worker.on("error", onError);
33+
worker.on("exit", onExit);
34+
}
35+
var workers = Math.max(1, Number.parseInt(process.env.WORKERS, 10)) || availableParallelism();
36+
while (workers !== 0) attachEvents(cluster.fork({ env })), --workers;

0 commit comments

Comments
 (0)