PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

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

PrepAway - Latest Free Exam Questions & Answers

Answer:

Explanation:

5 Comments on “Which code segment should you use?

  1. Raaph says:

    terminate() vs. close()

    The close() method is visible inside the worker’s scope. The terminate() method is a part of the worker object’s interface and can be called “from the outside”.

    If you create a worker in your main script and want to stop it from that script you should call the terminate() on the worker object. If you want to stop the worker from the worker code (for example as a response to an external message) you should call the close() method.

    So self.close(); is correct in this case.

    source: http://stackoverflow.com/questions/30500883/javascript-web-worker-close-vs-terminate




    0



    0

Leave a Reply