Skip to content

Commit

Permalink
fix: stdin splice (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Dec 14, 2023
1 parent c4565b7 commit 995573b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
7 changes: 6 additions & 1 deletion crates/js-component-bindgen/src/transpile_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,12 @@ impl<'a> Instantiator<'a, '_> {
.gen
.local_names
.get_or_create(
&format!("import:{}-{}", import_name, &func.name),
&format!(
"import:{}-{}-{}",
import_specifier,
maybe_iface_member.as_deref().unwrap_or(""),
&func.name
),
&func.name,
)
.0
Expand Down
32 changes: 7 additions & 25 deletions packages/preview2-shim/lib/io/worker-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,14 @@ class OutputStream {
return streamIoErrorCall(
OUTPUT_STREAM_SPLICE | this.#streamType,
this.#id,
src.#id,
len
{ src: src.#id, len }
);
}
blockingSplice(src, len) {
return streamIoErrorCall(
OUTPUT_STREAM_BLOCKING_SPLICE | this.#streamType,
this.#id,
inputStreamId(src),
len
{ src: inputStreamId(src), len }
);
}
subscribe() {
Expand Down Expand Up @@ -279,53 +277,37 @@ export const streams = { InputStream, OutputStream };

class Pollable {
#id;
#ready = false;
get _id() {
return this.#id;
}
ready() {
if (this.#ready) return true;
const ready = ioCall(POLL_POLLABLE_READY, this.#id);
if (ready) this.#ready = true;
return ready;
if (this.#id === 0) return true;
return ioCall(POLL_POLLABLE_READY, this.#id);
}
block() {
if (!this.#ready) {
ioCall(POLL_POLLABLE_BLOCK, this.#id);
this.#ready = true;
}
if (this.#id === 0) return;
ioCall(POLL_POLLABLE_BLOCK, this.#id);
}
static _getId(pollable) {
return pollable.#id;
}
static _create(id) {
const pollable = new Pollable();
pollable.#id = id;
if (id === 0) pollable.#ready = true;
return pollable;
}
static _markReady(pollable) {
pollable.#ready = true;
}
}

export const pollableCreate = Pollable._create;
delete Pollable._create;

const pollableMarkReady = Pollable._markReady;
delete Pollable._markReady;

const pollableGetId = Pollable._getId;
delete Pollable._getId;

export const poll = {
Pollable,
poll(list) {
const doneList = ioCall(POLL_POLL_LIST, null, list.map(pollableGetId));
for (const idx of doneList) {
pollableMarkReady(list[idx]);
}
return doneList;
return ioCall(POLL_POLL_LIST, null, list.map(pollableGetId));
},
};

Expand Down
5 changes: 2 additions & 3 deletions packages/preview2-shim/lib/io/worker-thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ function handle(call, id, payload) {
case INPUT_STREAM_CREATE | STDIN: {
const stream = createReadStream(null, {
fd: 0,
autoClose: false,
highWaterMark: 64 * 1024,
});
// for some reason fs streams dont emit readable on end
Expand Down Expand Up @@ -789,7 +788,7 @@ function handle(call, id, payload) {
for (const [idx, id] of payload.entries()) {
if (!unfinishedPolls.has(id)) doneList.push(idx);
}
if (doneList.length > 0) return doneList;
if (doneList.length > 0) return new Uint32Array(doneList);
// if all polls are promise type, we just race them
return Promise.race(
payload.map((id) => unfinishedPolls.get(id))
Expand All @@ -799,7 +798,7 @@ function handle(call, id, payload) {
}
if (doneList.length === 0)
throw new Error("poll promise did not unregister poll");
return doneList;
return new Uint32Array(doneList);
});
}

Expand Down
2 changes: 1 addition & 1 deletion submodules/wasmtime

0 comments on commit 995573b

Please sign in to comment.