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 # dom-worker-terminate-dev |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
terminate |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.