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
content / test / data / compute_pressure / observer-in-shared-worker.js [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
onconnect = function(e) {
const port = e.ports[0];
function pressureChange(data) {
port.postMessage({type: 'data', update: data[0].toJSON()});
}
const observer = new PressureObserver(pressureChange);
port.onmessage = async (e) => {
if (e.data.command == 'start') {
try {
await observer.observe('cpu');
port.postMessage({result: 'success'});
} catch (error) {
port.postMessage({result: 'fail'});
}
}
}
port.start();
}