1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.Messager = void 0;
|
7 | const fs_1 = __importDefault(require("fs"));
|
8 | const WorkerSetup_1 = require("./WorkerSetup");
|
9 | const output = WorkerSetup_1.WorkerSetup ? fs_1.default.createWriteStream("", { fd: 3 }) : null;
|
10 | var Messager;
|
11 | (function (Messager) {
|
12 | function send(message) {
|
13 | if (!output) {
|
14 | throw new Error("No output?");
|
15 | }
|
16 | const bufferLength = Buffer.allocUnsafe(2);
|
17 | const buffer = Buffer.from(JSON.stringify(message));
|
18 | bufferLength.writeUint16LE(buffer.length);
|
19 | return new Promise(resolve => {
|
20 | output.write(Buffer.concat([bufferLength, buffer]), resolve);
|
21 | });
|
22 | }
|
23 | Messager.send = send;
|
24 | })(Messager = exports.Messager || (exports.Messager = {}));
|