PressureObserver: phương thức takeRecords()
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 takeRecords() của giao diện PressureObserver trả về danh sách hiện tại các bản ghi áp lực được lưu trong pressure observer, đồng thời xóa rỗng nó.
Phương thức này hữu ích khi bạn muốn dừng quan sát một nguồn nhưng vẫn muốn đảm bảo nhận được các bản ghi chưa được truyền vào hàm callback của observer.
Cú pháp
takeRecords()
Tham số
Không có.
Giá trị trả về
Một Array các đối tượng PressureRecord.
Ví dụ
>Lấy các bản ghi
Ví dụ sau lưu danh sách hiện tại các bản ghi áp lực vào records và xóa rỗng pressure observer.
const observer = new PressureObserver(callback);
observer.observe("cpu");
const records = observer.takeRecords();
observer.disconnect(); // shut down observer now that we've taken records
if (records.length > 0) {
console.log(records[0].state);
console.log(records[0].time);
}
Thông số kỹ thuật
| Specification |
|---|
| Compute Pressure Level 1> # the-takerecords-method> |