1
0
Fork 0
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:
Andreu Botella 2021-09-13 13:47:17 +02:00 committed by GitHub
parent d0b5ff6db9
commit 93290487eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View file

@ -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 {};

View file

@ -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