Re: [compute-pressure] Get rid of the promise returned by observe (#258)

So the spec patch is quite simple (I have one local).

Problem is our implementation and testing. We only active the backend when needed and that could in theory fail but is not expected to, anymore than the browser compositor thread could fail :-)

Also users just observe and get events as soon as the system can deliver them. If the pressure source is supported and requirements (like focused window) are met, then events are expected to be delivered.

I thought about wrapping things in a promise and adding a little timeout in the case things break, like

```js
function observe(callback, ...args) {
  return new Promise(async (resolve, reject) => {
    const id = setTimeout(reject, 4_000);
    const observer = new PressureObserver(cargs => {
      clearTimeout(id);
      resolve();
      callback(...cargs);
    })
    await observer.observe(...args)
  })
}

observe(console.log, "cpu")
```

But @arskama says we cannot use setTimeout in tests. Not sure what the other best way would be for generic upstreamable tests.

@rakuco 

Could we send a failure event just for tests? Potentially we could send the "failure" state or similar

-- 
GitHub Notification of comment by kenchris
Please view or discuss this issue at https://github.com/w3c/compute-pressure/issues/258#issuecomment-2045382376 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 9 April 2024 14:52:48 UTC