1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00
denoland-deno/tests/testdata/run/worker_message_before_close.js

27 lines
621 B
JavaScript
Raw Normal View History

const messagesReceived = new Set();
for (let i = 0; i < 4; i++) {
const worker = new Worker(
import.meta.resolve("../workers/message_before_close.js"),
{ type: "module", name: String(i) },
);
worker.addEventListener("message", () => {
messagesReceived.add(i);
if (messagesReceived.size == 4) {
console.log("received all 4 responses from the workers");
}
});
worker.postMessage({});
}
globalThis.addEventListener("unload", () => {
if (messagesReceived.size !== 4) {
console.log(
"received only %d responses from the workers",
messagesReceived.size,
);
}
});