HOTSPOT
You are creating a web worker for an HTML5 application. The following tasks must be performed from within the web worker:
Register an event listener for the web worker
Start and stop the web worker
You need to define a function that performs the required tasks.
Which code segment should you use? (To answer, select the appropriate option from the drop-down list in the answer area.)
A.
The most probably correct answer is invalid.
The code with:
<<
<<self.addEventListener('message',function(event));
<<
cause error. The body of callback method is missing. Correct answer should be rather:
<<
<< self.addEventListener('message',function(event){
<<
Pay attention on the end of line;
For Stop: It should be self.terminate(), the is no close method for worker process.
Re stop: There are two ways to stop a worker: by calling worker.terminate() from the main page or by calling self.close() inside of the worker itself. As it has been performed from within a web worker it should be self.close() in this case.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
Here are some links to websites that we link to mainly because we believe they’re worth visiting.