Re: [wake-lock] WakeLock.request() returns a promise that never resolves (#226)

> It sounds like you want to revert back to a more complex WakeLock object which dispatches an event when the lock state changes.

Could the promise resolve with some sort of result object, so the following could work (reduced to just the relevant bits):

```js
try {
  const wakeLock = await WakeLock.request('screen', {signal});
  console.log(`🙌 Yay, Wake Lock of type ${wakeLock.type} is active!`);

  // The event name `"wakelockintervention"` is made up
  wakeLock.addEventListener('wakelockintervention', (e) => {
    console.error(`😱 The UA terminated Wake Lock ${e.target.type}.`);
  });
} catch (e) {
  // Regular abort 
  if (e.name === 'AbortError') {
    console.log('✅ All fine, Wake Lock aborted');
  } else {
    // Something went wrong during acquiring
    console.error('🚫', e.name, e.message);
   }
}
```


-- 
GitHub Notification of comment by tomayac
Please view or discuss this issue at https://github.com/w3c/wake-lock/issues/226#issuecomment-519438950 using your GitHub account

Received on Thursday, 8 August 2019 09:16:40 UTC