UNPKG

parallel-park

Version:

Parallel/concurrent async work, optionally using multiple processes

27 lines (26 loc) 938 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.readUntilEnd = void 0; const debug_1 = __importDefault(require("debug")); const debug = (0, debug_1.default)("parallel-park:read-until-end"); let streamId = 0; function readUntilEnd(stream) { const id = `${process.pid}-${streamId}`; streamId++; return new Promise((resolve) => { let data = ""; stream.on("data", (chunk) => { const chunkStr = chunk.toString("utf-8"); debug("received data chunk from stream %s: %o", id, chunkStr); data += chunkStr; }); stream.on("close", () => { debug("stream %s closed; resolving with: %o", id, data); resolve(data); }); }); } exports.readUntilEnd = readUntilEnd;