UNPKG

981 BJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.Messager = void 0;
7const fs_1 = __importDefault(require("fs"));
8const WorkerSetup_1 = require("./WorkerSetup");
9const output = WorkerSetup_1.WorkerSetup ? fs_1.default.createWriteStream("", { fd: 3 }) : null;
10var 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 = {}));