2025-03-18 15:28:35 -03:00
|
|
|
<!DOCTYPE html>
|
2023-11-22 13:57:22 -03:00
|
|
|
<script src="../include.js"></script>
|
|
|
|
|
<script>
|
|
|
|
|
asyncTest((done) => {
|
|
|
|
|
let work = new Worker("worker.js");
|
2023-12-20 17:47:01 -03:00
|
|
|
let channel = new MessageChannel();
|
|
|
|
|
|
|
|
|
|
function finishTest() {
|
|
|
|
|
println("DONE");
|
|
|
|
|
work.onmessage = null;
|
|
|
|
|
work.terminate();
|
|
|
|
|
channel.port2.onmessage = null;
|
|
|
|
|
done();
|
|
|
|
|
}
|
2023-11-22 13:57:22 -03:00
|
|
|
let count = 0;
|
|
|
|
|
work.onmessage = (evt) => {
|
|
|
|
|
println("Got message from worker: " + JSON.stringify(evt.data));
|
|
|
|
|
count++;
|
2023-12-20 17:47:01 -03:00
|
|
|
if (count === 3) {
|
|
|
|
|
finishTest();
|
2023-11-22 13:57:22 -03:00
|
|
|
}
|
|
|
|
|
};
|
2023-12-20 17:47:01 -03:00
|
|
|
channel.port2.onmessage = (evt) => {
|
|
|
|
|
println("Got message from port: " + JSON.stringify(evt.data));
|
|
|
|
|
channel.port2.postMessage("Hello from port2");
|
|
|
|
|
count++;
|
|
|
|
|
if (count === 3) {
|
|
|
|
|
finishTest();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
work.postMessage({ port: channel.port1 }, { transfer : [channel.port1]});
|
2023-11-22 13:57:22 -03:00
|
|
|
});
|
|
|
|
|
</script>
|