Changes

Jump to: navigation, search

DPS921/Web Worker API

559 bytes added, 20:44, 4 December 2020
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>
45
edits

Navigation menu