While most of the time we want to keep the boundaries up between our workers and tabs of our applications, there will be times when we want to just share the data or even the worker among every instance. When this is the case, we can utilize two systems, SharedWorker and SharedArrayBuffer.
SharedWorker is just what it sounds like, when one spins up, just like BroadcastChannel, and someone else makes the same call to create a SharedWorker, it will just connect to the already created instance. Let's go ahead and do just this:
- We will create a new file for the SharedWorker JavaScript code. Inside of here, put some general computing functions such as adding and subtracting:
const add = function(a, b) {
return a + b;
}
const mult = function(a, b) {
return a * b;
}
const divide = function(a, b) {
return a / b;
}
const remainder = function(a, b) {
...