Skip to content

Commit

Permalink
fix: move stdio to main thread (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Nov 16, 2023
1 parent 18c47bf commit 2026b68
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 124 deletions.
17 changes: 8 additions & 9 deletions packages/preview2-shim/lib/io/worker-io.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fileURLToPath } from "node:url";
import { createSyncFn } from "../synckit/index.js";
import * as calls from "./calls.js";
import * as streamTypes from "./stream-types.js";
import { STDERR } from "./stream-types.js";

const DEBUG = false;

Expand Down Expand Up @@ -38,8 +38,6 @@ if (DEBUG) {
};
}

export { streamTypes };

const symbolDispose = Symbol.dispose || Symbol.for("dispose");

class ComponentError extends Error {
Expand Down Expand Up @@ -145,13 +143,18 @@ class OutputStream {
);
}
write(buf) {
if (this.#streamType <= STDERR) return this.blockingWriteAndFlush(buf);
return streamIoErrorCall(
calls.OUTPUT_STREAM_WRITE | this.#streamType,
this.#id,
buf
);
}
blockingWriteAndFlush(buf) {
if (this.#streamType <= STDERR) {
const stream = this.#streamType === STDERR ? process.stderr : process.stdout;
return void stream.write(buf);
}
return streamIoErrorCall(
calls.OUTPUT_STREAM_BLOCKING_WRITE_AND_FLUSH | this.#streamType,
this.#id,
Expand Down Expand Up @@ -213,13 +216,9 @@ class OutputStream {
* @param {OutputStreamType} streamType
* @param {any} createPayload
*/
static _create(streamType, createPayload) {
static _create(streamType, id) {
const stream = new OutputStream();
stream.#id = ioCall(
calls.OUTPUT_STREAM_CREATE | streamType,
null,
createPayload
);
stream.#id = id;
stream.#streamType = streamType;
return stream;
}
Expand Down
Loading

0 comments on commit 2026b68

Please sign in to comment.