PrepAway - Latest Free Exam Questions & Answers

You are developing a web page that performs CPU-intensive calculations. A web worker processes these calculati

You are developing a web page that performs CPU-intensive calculations. A web worker processes these calculations on a separate background thread. The process is instantiated from the web page.

You need to stop the web worker process after the calculations are completed.

Which two actions can you perform to achieve this goal? (Each correct answer presents a complete solution. Choose two.)

A. From the web page, call the close() method.

B. From the web worker process, call the terminate() method.

C. From the web page, call the terminate() method.

D. From the web worker process, call the close() method.

Explanation:

Terminating a worker

If you need to immediately terminate a running worker, you can do so by calling the workers terminate() method:

myWorker.terminate();

The worker thread is killed immediately without an opportunity to complete its operations or clean up after itself.

Workers may close themselves by calling their own close method:

close();

Reference: Using Web Workers


Leave a Reply