mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -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++) {
|
||||
const worker = new Worker(
|
||||
new URL("./workers/message_before_close.js", import.meta.url).href,
|
||||
{ type: "module", name: String(i) },
|
||||
);
|
||||
|
||||
worker.addEventListener("message", (message) => {
|
||||
// Only print responses after all reception logs.
|
||||
setTimeout(() => {
|
||||
console.log("response from worker %d received", message.data);
|
||||
}, 500);
|
||||
worker.addEventListener("message", () => {
|
||||
messagesReceived += 1;
|
||||
|
||||
if (messagesReceived == 4) {
|
||||
console.log("received all 4 responses from the workers");
|
||||
}
|
||||
});
|
||||
|
||||
worker.postMessage(i);
|
||||
}
|
||||
|
||||
globalThis.addEventListener("unload", () => {
|
||||
if (messagesReceived !== 4) {
|
||||
console.log(
|
||||
"received only %d responses from the workers",
|
||||
messagesReceived,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export {};
|
||||
|
|
|
@ -2,7 +2,4 @@ message received in worker 0
|
|||
message received in worker 1
|
||||
message received in worker 2
|
||||
message received in worker 3
|
||||
response from worker 0 received
|
||||
response from worker 1 received
|
||||
response from worker 2 received
|
||||
response from worker 3 received
|
||||
received all 4 responses from the workers
|
||||
|
|
Loading…
Reference in a new issue