-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
65 lines (47 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: "PressureObserver: disconnect() method"
short-title: disconnect()
slug: Web/API/PressureObserver/disconnect
page-type: web-api-instance-method
status:
- experimental
browser-compat: api.PressureObserver.disconnect
---
{{APIRef("Compute Pressure API")}}{{SeeCompatTable}}{{securecontext_header}}
The **`disconnect()`** method of the {{domxref('PressureObserver')}} interface stops the pressure observer callback from receiving pressure records from all sources.
## Syntax
```js-nolint
disconnect()
```
### Parameters
None.
### Return value
None ({{jsxref("undefined")}}).
## Examples
### Stopping a pressure observer
The following example collects 20 samples and then disconnects the pressure observer to disable receiving any more pressure records.
```js
const samples = [];
function pressureChange(records, observer) {
for (const record of records) {
samples.push(record.state);
// We only want 20 samples
if (samples.length === 20) {
observer.disconnect();
return;
}
}
}
try {
const observer = new PressureObserver(callback);
await observer.observe("cpu", {
sampleInterval: 1000, // 1000ms
});
} catch (error) {
// report error setting up the observer
}
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}