-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
51 lines (32 loc) · 1.28 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
title: "Worker: terminate() method"
short-title: terminate()
slug: Web/API/Worker/terminate
page-type: web-api-instance-method
browser-compat: api.Worker.terminate
---
{{APIRef("Web Workers API")}}{{AvailableInWorkers("window_and_worker_except_service")}}
The **`terminate()`** method of the {{domxref("Worker")}} interface immediately terminates the {{domxref("Worker")}}. This does not offer the worker an opportunity to finish its operations; it is stopped at once.
## Syntax
```js-nolint
terminate()
```
### Parameters
None.
### Return value
None ({{jsxref("undefined")}}).
## Examples
The following code snippet shows creation of a {{domxref("Worker")}} object using the {{domxref("Worker.Worker", "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 {{domxref("Worker")}} instance using the {{domxref("DedicatedWorkerGlobalScope.close()")}} or {{domxref("SharedWorkerGlobalScope.close()")}} methods.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("Worker")}} interface
- {{domxref("DedicatedWorkerGlobalScope.close()")}}
- {{domxref("SharedWorkerGlobalScope.close()")}}