@genroc/eval-node 0.0.0-edge.88591fb → 0.0.0-edge.a5e8589

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/realm.js +10 -1
  2. package/package.json +1 -1
  3. package/realm.ts +11 -1
package/dist/realm.js CHANGED
@@ -97,8 +97,17 @@ async function run(req) {
97
97
  return { ok: false, failure: describe(err, "nonserializable") };
98
98
  }
99
99
  }
100
+ // The realm's stdio is a pipe to the host thread, and eval.ts terminates this thread the moment
101
+ // the reply lands — so whatever a script wrote last is still in the pipe when it dies. An empty
102
+ // write's callback fires once the queue ahead of it has drained, which makes the reply a barrier
103
+ // for `console` and a direct process.stdout.write alike: both are this stream.
104
+ function flush(stream) {
105
+ return new Promise((resolve) => stream.write("", () => resolve()));
106
+ }
100
107
  // Non-null because this module only ever runs as a worker entry point; a null port here
101
108
  // would mean eval.ts loaded it as a plain module, which nothing does.
102
109
  parentPort.on("message", async (req) => {
103
- parentPort.postMessage(await run(req));
110
+ const reply = await run(req);
111
+ await Promise.all([flush(process.stdout), flush(process.stderr)]);
112
+ parentPort.postMessage(reply);
104
113
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genroc/eval-node",
3
- "version": "0.0.0-edge.88591fb",
3
+ "version": "0.0.0-edge.a5e8589",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
package/realm.ts CHANGED
@@ -99,8 +99,18 @@ async function run(req: WorkerRequest): Promise<WorkerReply> {
99
99
  }
100
100
  }
101
101
 
102
+ // The realm's stdio is a pipe to the host thread, and eval.ts terminates this thread the moment
103
+ // the reply lands — so whatever a script wrote last is still in the pipe when it dies. An empty
104
+ // write's callback fires once the queue ahead of it has drained, which makes the reply a barrier
105
+ // for `console` and a direct process.stdout.write alike: both are this stream.
106
+ function flush(stream: NodeJS.WriteStream): Promise<void> {
107
+ return new Promise((resolve) => stream.write("", () => resolve()));
108
+ }
109
+
102
110
  // Non-null because this module only ever runs as a worker entry point; a null port here
103
111
  // would mean eval.ts loaded it as a plain module, which nothing does.
104
112
  parentPort!.on("message", async (req: WorkerRequest) => {
105
- parentPort!.postMessage(await run(req));
113
+ const reply = await run(req);
114
+ await Promise.all([flush(process.stdout), flush(process.stderr)]);
115
+ parentPort!.postMessage(reply);
106
116
  });