Refactored dotnetbuilderwrapper to use promises; fixed a bug causing incomplete data from wrapper

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent b1340eab1f
commit 78ed651184
  1. 41
      BuildServer/lib/tasks/dotnetbuilderwrapper.ts

@ -7,25 +7,40 @@ import { WritableStreamBuffer } from "stream-buffers";
import settings from "../../settings"; import settings from "../../settings";
const wrapBuilder = (builder, input, onExit) => { const wrapBuilder = (builder, input, onExit) => {
const resultBuffer = new WritableStreamBuffer(); const stdoutPromise = new Promise((resolve, reject) => {
const errorBuffer = new WritableStreamBuffer(); const streamBuffer = new WritableStreamBuffer();
builder.stdout
builder.stdout.on("data", (data) => { .on("error", reject)
resultBuffer.write(data); .pipe(streamBuffer)
.on("error", reject)
.on("finish", () => {
streamBuffer.end();
resolve(streamBuffer.getContentsAsString());
});
}); });
builder.stderr.on("data", (data) => { const stderrPromise = new Promise((resolve, reject) => {
errorBuffer.write(data); const streamBuffer = new WritableStreamBuffer();
builder.stderr
.on("error", reject)
.pipe(streamBuffer)
.on("error", reject)
.on("finish", () => {
streamBuffer.end();
resolve(streamBuffer.getContentsAsString());
});
}); });
builder.on("exit", (code) => { const builderPromise = new Promise((resolve, reject) => {
resultBuffer.end(); builder.stdin.write(input);
errorBuffer.end(); builder.stdin.end();
onExit(code, resultBuffer.getContentsAsString(), errorBuffer.getContentsAsString()); builder.on("exit", resolve);
}); });
builder.stdin.write(input); Promise.all([stdoutPromise, stderrPromise, builderPromise]).then((values) => {
builder.stdin.end(); const [result, builderError, code] = values;
onExit(code, result, builderError);
}).catch((err) => onExit(0, undefined, err));
}; };
export default ((params, processor) => () => { export default ((params, processor) => () => {

Loading…
Cancel
Save