- From: Florian Scholz via GitHub <sysbot+gh@w3.org>
- Date: Mon, 01 Apr 2024 16:08:13 +0000
- To: public-device-apis-log@w3.org
Elchi3 has just created a new issue for https://github.com/w3c/compute-pressure:
== PressureObserver options object: constructor vs observe method ==
Currently, `sampleInterval` is an option of the `PressureObserver` constructor. If I want to create several pressure observers, I guess my code would look like this:
```js
const cpuObserver = new PressureObserver(callback, { sampleInterval: 1500 });
await cpuObserver.observe("cpu");
const cpuObserverHighSampleRate = new PressureObserver(callback, { sampleInterval: 7000 });
await cpuObserverHighSampleRate.observe("cpu");
const gpuObserver = new PressureObserver(callback, { sampleInterval: 2500 });
await gpuObserver.observe("gpu");
```
In other APIs, for example for the `PerformanceObserver`, the options are on the `observe` method. If that would be the case for this API, I could write code like this:
```js
const observer = new PressureObserver(callback);
await observer.observe("cpu", { sampleInterval: 1500 });
await observer.observe("cpu", { sampleInterval: 7000 });
await observer.observe("gpu", { sampleInterval: 2500 });
```
Not sure if having multiple pressure observers is typical but I guess if I had multiple of them, I likely want to have different sources or options. I see that "cpu" is the only source and `sampleInterval` is the only option for now, though, so maybe this will only matter if this API offers more sources and more options in the future.
Even more future proof:
```js
await observer.observe({ sources: ["cpu"], sampleInterval: 2500 });
```
Please view or discuss this issue at https://github.com/w3c/compute-pressure/issues/256 using your GitHub account
--
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Monday, 1 April 2024 16:08:14 UTC