Skip to content

Commit 4cbd5ef

Browse files
committed
Fix repl by updating withCreateProcess implementation
1 parent 3a3b9f7 commit 4cbd5ef

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

bin/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,13 @@ server.post("withCreateProcess", (request) => {
176176
tmp.file((err, path, fd) => {
177177
if (err) throw err;
178178

179-
const reader = fs.createReadStream(path);
180-
181-
reader.on("open", () => {
182179
nextCounter += 1;
180+
181+
fs.createReadStream(path)
182+
.on("data", (chunk) => {
183+
processes[nextCounter].stdin.end(chunk);
184+
});
185+
183186
processes[nextCounter] = child_process.spawn(
184187
createProcess.cmdspec.cmd,
185188
createProcess.cmdspec.args,
@@ -194,11 +197,6 @@ server.post("withCreateProcess", (request) => {
194197

195198
request.respond(200, null, JSON.stringify({ stdinHandle: fd, ph: nextCounter }));
196199
});
197-
198-
reader.on("data", (chunk) => {
199-
processes[nextCounter].stdin.end(chunk);
200-
});
201-
});
202200
});
203201

204202
server.post("hClose", (request) => {
@@ -208,7 +206,8 @@ server.post("hClose", (request) => {
208206
});
209207

210208
server.post("waitForProcess", (request) => {
211-
processes[request.body].on("exit", (code) => {
209+
const ph = parseInt(request.body);
210+
processes[ph].on("exit", (code) => {
212211
request.respond(200, null, code);
213212
});
214213
});

0 commit comments

Comments
 (0)