mirror of
https://github.com/denoland/deno.git
synced 2025-01-05 05:49:20 -05:00
fix: worker_message_before_close was flaky (#12019)
This commit is contained in:
parent
d0b5ff6db9
commit
93290487eb
2 changed files with 19 additions and 9 deletions
|
@ -1,16 +1,29 @@
|
||||||
|
let messagesReceived = 0;
|
||||||
|
|
||||||
for (let i = 0; i < 4; i++) {
|
for (let i = 0; i < 4; i++) {
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("./workers/message_before_close.js", import.meta.url).href,
|
new URL("./workers/message_before_close.js", import.meta.url).href,
|
||||||
{ type: "module", name: String(i) },
|
{ type: "module", name: String(i) },
|
||||||
);
|
);
|
||||||
|
|
||||||
worker.addEventListener("message", (message) => {
|
worker.addEventListener("message", () => {
|
||||||
// Only print responses after all reception logs.
|
messagesReceived += 1;
|
||||||
setTimeout(() => {
|
|
||||||
console.log("response from worker %d received", message.data);
|
if (messagesReceived == 4) {
|
||||||
}, 500);
|
console.log("received all 4 responses from the workers");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
worker.postMessage(i);
|
worker.postMessage(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
globalThis.addEventListener("unload", () => {
|
||||||
|
if (messagesReceived !== 4) {
|
||||||
|
console.log(
|
||||||
|
"received only %d responses from the workers",
|
||||||
|
messagesReceived,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export {};
|
export {};
|
||||||
|
|
|
@ -2,7 +2,4 @@ message received in worker 0
|
||||||
message received in worker 1
|
message received in worker 1
|
||||||
message received in worker 2
|
message received in worker 2
|
||||||
message received in worker 3
|
message received in worker 3
|
||||||
response from worker 0 received
|
received all 4 responses from the workers
|
||||||
response from worker 1 received
|
|
||||||
response from worker 2 received
|
|
||||||
response from worker 3 received
|
|
||||||
|
|
Loading…
Reference in a new issue