Web APIs
Worker.prototype.terminate()
Stops a dedicated worker without waiting for its ongoing tasks or cleanup to finish.
Formal Syntax & Structure
javascript syntaxjavascript
worker.terminate()Return Value
undefined
Stops a dedicated worker without waiting for its ongoing tasks or cleanup to finish.
Working Example
Example Snippetjavascript
(async () => {const url=URL.createObjectURL(new Blob(['self.onmessage=e=>self.postMessage(e.data);'],{type:"text/javascript"}));let w;try{w=new Worker(url);console.log(String(w.terminate()));}finally{w?.terminate();URL.revokeObjectURL(url);}})()