45
edits
Changes
→Dedicated Worker
}
}
</pre>
The code that the worker runs is the following ('''[https://github.com/vitokhangnguyen/WebWorkerDemo/blob/main/scripts/dedicatedWorker.js dedicatedWorker.js]'''):
<pre>
importScripts('./sobel.js');
// Retrieve message (data) from the script that created the worker
self.onmessage = function (event) {
// Set worker ID
const index = event.data.index;
// Get data and call the Sobel filter
const sobelData = Sobel(event.data.data);
// Post the data back on completion
self.postMessage({ result: sobelData, index: index});
};
</pre>