PrepAway - Latest Free Exam Questions & Answers

Which two actions can you perform to achieve this goal?

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.)

PrepAway - Latest Free Exam Questions & Answers

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 worker’s 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();
Using Web Workers

2 Comments on “Which two actions can you perform to achieve this goal?

  1. itool says:

    I´m not so familiar with web workers, but as far as I understand, the answer is correct.

    The close method is visible from inside the scope of the worker. Therefore, calling the close function from the webworker after the calculation would terminate the process.

    The terminate method is visible from outside the scope of the worker. Therefore, if the process is instantiated from the webpage it can be shut down using terminate.

    Again, I don´t have experience with webworkers but it is the way I understand it after reading a bit on the topic.

    Sources: Sections 4.1 and 4.2 from http://cs.sru.edu/~zhou/web/WebWorker.html




    3



    0

Leave a Reply