Skip to content

Commit 72cdb9a

Browse files
committed
JS loop: io_run is replaced too, not only io_exit: bend x.bend runs a program in-process through io_run and keeps its number as the exit code, so with the Bun loop the default its parks reached the old sync loop, which saw no waits and stopped ("deadlock"); both start bp_run and exit with its code
1 parent 4e0b0e0 commit 72cdb9a

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

‎src/server/effects/loop.js‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,17 +1203,31 @@ async function bp_run(m) {
12031203
}
12041204
}
12051205

1206+
// A program runs either from its emitted file (io_exit(main, show) at its
1207+
// end) or inside `bend x.bend`, which calls io_run(main) and keeps the
1208+
// number it answers as process.exitCode, then lets the process end when
1209+
// nothing is left. Both start bp_run and exit with its code when it ends;
1210+
// io_run answers 0 at once (Bun's pending work keeps the process up until
1211+
// then, and a run nothing can finish ends at beforeExit as a deadlock).
1212+
function bp_start(main) {
1213+
bp_run(main).then((code) => process.exit(code), (e) => {
1214+
io_errs(e instanceof RangeError
1215+
? "bend: memory fault (machine stack overflow?)" : String(e));
1216+
process.exit(1);
1217+
});
1218+
}
1219+
12061220
if (BP_ASYNC) {
12071221
const sync_exit = io_exit;
12081222
io_exit = function (main, show) {
12091223
if (show !== null) {
12101224
return sync_exit(main, show);
12111225
}
1212-
bp_run(main).then((code) => process.exit(code), (e) => {
1213-
io_errs(e instanceof RangeError
1214-
? "bend: memory fault (machine stack overflow?)" : String(e));
1215-
process.exit(1);
1216-
});
1226+
bp_start(main);
1227+
};
1228+
io_run = function (main) {
1229+
bp_start(main);
1230+
return 0;
12171231
};
12181232
}
12191233

0 commit comments

Comments
 (0)