Worker: terminate() method
Note: This feature is available in Web Workers, except for Service Workers.
The terminate()
method of the Worker
interface immediately terminates the Worker
. This does not offer the worker an opportunity to finish its operations; it is stopped at once.
Syntax
js
terminate()
Parameters
None.
Return value
None (undefined
).
Examples
The following code snippet shows creation of a Worker
object using the Worker()
constructor, which is then immediately terminated.
js
const myWorker = new Worker("worker.js");
myWorker.terminate();
Note: DedicatedWorkers and SharedWorkers can also be stopped from the Worker
instance using the DedicatedWorkerGlobalScope.close()
or SharedWorkerGlobalScope.close()
methods.
Specifications
Specification |
---|
HTML Standard # dom-worker-terminate-dev |
Browser compatibility
BCD tables only load in the browser