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 GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
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.

See also