UNPKG

@gameye/sdk

Version:
30 lines 985 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Read stream until the waitFor function returns true, then * pause the stream. * @param stream stream to read * @param waitFor return true to resolve */ async function streamWait(stream, waitFor = (() => true)) { return new Promise((resolve, reject) => { stream.addListener("data", onData); stream.addListener("error", onError); stream.resume(); function onData(chunk) { if (waitFor(chunk)) { stream.pause(); stream.removeListener("data", onData); stream.removeListener("error", onError); resolve(chunk); } } function onError(error) { stream.removeListener("data", onData); stream.removeListener("error", onError); reject(error); } }); } exports.streamWait = streamWait; //# sourceMappingURL=stream-wait.js.map