Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match simple-shared-worker/multiply.js to use same event-handler loop as simple-web-worker/main.js #284

Merged
merged 6 commits into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading