Skip to content

Commit 3f0fc2b

Browse files
committed
test
1 parent 50eaf5f commit 3f0fc2b

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/webworker/js.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ console.debug('Initializing worker');
3737
3838
const worker_result = await fn(arg, event.ports[0]);
3939
40+
// For channel tasks, yield the event loop before posting the result.
41+
// Channel messages (sent via MessagePort.postMessage during execution)
42+
// and the task result (sent via self.postMessage) travel on independent
43+
// message paths. Without this yield, the main thread may receive the
44+
// result before all channel messages have been delivered.
45+
if (is_channel) {
46+
await new Promise(resolve => setTimeout(resolve, 0));
47+
}
48+
4049
// Send response back to be handled by callback in main thread.
4150
console.debug('Send worker result');
4251
self.postMessage({ id: id, response: worker_result });
@@ -103,6 +112,12 @@ initHandler = async function(event) {
103112
104113
const worker_result = await fn(arg, event.ports[0]);
105114
115+
// For channel tasks, yield the event loop before posting the result.
116+
// See comment in WORKER_JS for rationale.
117+
if (is_channel) {
118+
await new Promise(resolve => setTimeout(resolve, 0));
119+
}
120+
106121
// Send response back to be handled by callback in main thread.
107122
console.debug('Send worker result');
108123
self.postMessage({ id: id, response: worker_result });

test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ keywords.workspace = true
1616
crate-type = ["cdylib"]
1717

1818
[dependencies]
19-
futures = "0.3"
2019
serde = { version = "1.0", features = ["derive"] }
20+
tokio = { version = "1.4", features = ["sync"] }
2121
wasm-bindgen = "0.2"
2222
wasm-bindgen-futures = "0.4"
2323
web-sys = { version = "0.3", features = ["MessagePort"] }

0 commit comments

Comments
 (0)