W3C home > Mailing lists > Public > public-device-apis-log@w3.org > August 2019

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

From: Thomas Steiner via GitHub <sysbot+gh@w3.org>
Date: Thu, 08 Aug 2019 09:16:38 +0000
To: public-device-apis-log@w3.org
Message-ID: <issue_comment.created-519438950-1565255797-sysbot+gh@w3.org>
> 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

This archive was generated by hypermail 2.3.1 : Thursday, 8 August 2019 09:16:41 UTC