DedicatedWorkerGlobalScope.close()

The close() method of the DedicatedWorkerGlobalScope interface discards any tasks queued in the DedicatedWorkerGlobalScope's event loop, effectively closing this particular scope.

Syntax

self.close();

Example

If you want to close your worker instance from inside the worker itself, you can call the following:

close();

close() and self.close() are effectively equivalent — both represent close() being called from inside the worker's inner scope.

Note: There is also a way to stop the worker from the main thread: the Worker.terminate method.

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'close()' in that specification.
Living Standard

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
closeChrome Full support YesEdge Full support ≤79Firefox Full support 54IE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 54Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes

Legend

Full support
Full support
Compatibility unknown
Compatibility unknown

See also

DedicatedWorkerGlobalScope