Skip to content

Commit

Permalink
Match simple-shared-worker/multiply.js to use same event-handler lo…
Browse files Browse the repository at this point in the history
…op as `simple-web-worker/main.js` (#284)

* Match `simple-shared-worker/multiply.js` to use same event-handler loop logic as `simple-web-worker/main.js`

* `myWorker.postMessage` => `myWorker.port.postMessage`

* Update web-workers/simple-shared-worker/multiply.js

* Update web-workers/simple-shared-worker/multiply.js

---------

Co-authored-by: Brian Smith <[email protected]>
  • Loading branch information
Marcial1234 and bsmth authored Dec 30, 2024
1 parent b0f3c05 commit 5970eb3
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions web-workers/simple-shared-worker/multiply.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ const result1 = document.querySelector(".result1");
if (!!window.SharedWorker) {
const myWorker = new SharedWorker("worker.js");

first.onchange = function () {
myWorker.port.postMessage([first.value, second.value]);
console.log("Message posted to worker");
};

second.onchange = function () {
myWorker.port.postMessage([first.value, second.value]);
console.log("Message posted to worker");
};
[first, second].forEach(input => {
input.onchange = () => {
myWorker.port.postMessage([first.value, second.value]);
console.log('Message posted to worker');
}
})

myWorker.port.onmessage = function (e) {
myWorker.port.onmessage = (e) => {
result1.textContent = e.data;
console.log("Message received from worker");
console.log(e.lastEventId);
Expand Down

0 comments on commit 5970eb3

Please sign in to comment.