PressureObserver: phương thức disconnect()
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Note: This feature is available in Web Workers, except for Service Workers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Phương thức disconnect() của giao diện PressureObserver dừng hàm callback của pressure observer nhận bản ghi áp lực từ tất cả các nguồn.
Cú pháp
js
disconnect()
Tham số
Không có.
Giá trị trả về
Không có (undefined).
Ví dụ
>Dừng một pressure observer
Ví dụ sau thu thập 20 mẫu rồi ngắt kết nối pressure observer để không nhận thêm bản ghi áp lực nào.
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
}
Thông số kỹ thuật
| Specification |
|---|
| Compute Pressure Level 1> # dom-pressureobserver-disconnect> |