Skip to content

Commit

Permalink
feat: add a proper termination of the worker
Browse files Browse the repository at this point in the history
  • Loading branch information
owulveryck committed Nov 18, 2023
1 parent 4e1e7b5 commit 72002e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ window.onload = function() {
document.getElementById('content').src = presentURL;
}
};
// connectWebSocket();

// Add an event listener for the 'beforeunload' event, which is triggered when the page is refreshed or closed
window.addEventListener('beforeunload', () => {
// Send a termination signal to the worker before the page is unloaded
streamWorker.postMessage({ type: 'terminate' });
eventWorker.postMessage({ type: 'terminate' });
});
5 changes: 4 additions & 1 deletion client/worker_event_processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ onmessage = (event) => {
rotate = event.data.rotate;
// Handle the error, maybe show a user-friendly message or take some corrective action
break;

case 'terminate':
console.log("terminating worker");
close();
break;
}
};

Expand Down
5 changes: 5 additions & 0 deletions client/worker_stream_processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ onmessage = (event) => {
withColor = event.data.withColor;
// Handle the error, maybe show a user-friendly message or take some corrective action
break;
case 'terminate':
console.log("terminating worker");
close();
break;

}
};

Expand Down

0 comments on commit 72002e1

Please sign in to comment.