Attempt to rewrite a bit

This commit is contained in:
Radon Rosborough 2023-01-04 20:03:58 -07:00
parent 976adad108
commit 33b56682ac
1 changed files with 8 additions and 11 deletions

View File

@ -1,4 +1,5 @@
import { spawn } from "child_process"; import { spawn } from "child_process";
import * as fsBase from "fs";
import { promises as fs } from "fs"; import { promises as fs } from "fs";
import process from "process"; import process from "process";
@ -203,27 +204,23 @@ export function deptyify({ handlePtyInput, handlePtyExit }) {
handlePtyExit(status); handlePtyExit(status);
triggerDone(); triggerDone();
}); });
const [input, output] = await new Promise((resolve, reject) => { const output = await new Promise((resolve, reject) => {
setTimeout(() => reject("timed out"), 5000); setTimeout(() => reject("timed out"), 5000);
resolve( resolve(fs.open(`${dir.path}/output`, "w"));
Promise.all([
fs.open(`${dir.path}/input`, "r"),
fs.open(`${dir.path}/output`, "w"),
])
);
}); });
const input = fsBase.createReadStream(`${dir.path}/input`);
setTimeout(async () => { setTimeout(async () => {
try { try {
while (true) { for await (const data of input) {
handlePtyInput((await input.read()).buffer); handlePtyInput(data);
} }
} catch (err) { } catch (err) {
logError(err); logError(err);
} }
}, 0); }, 0);
resolve({ resolve({
handlePtyOutput: async (data) => { handlePtyOutput: (data) => {
await output.write(data); output.write(data);
}, },
}); });
}, },