Worker: terminate() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
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
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.
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
Loading…