Worker: terminate() method
Web Workers APIwindowandworkerexceptservice
Web Workers APIwindow_and_worker_except_service
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
Browser compatibility
See also
- Worker interface
- DedicatedWorkerGlobalScope.close()
- SharedWorkerGlobalScope.close()