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

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

From: Raphael Kubo da Costa via GitHub <sysbot+gh@w3.org>
Date: Fri, 04 Oct 2019 13:13:52 +0000
To: public-device-apis-log@w3.org
Message-ID: <issue_comment.created-538391442-1570194832-sysbot+gh@w3.org>
> > How is `WakeLockSentinel.release()` supposed to behave when an event such as a page visibility change happens? Is it supposed to do nothing, return a rejected promise or none of the above?
> My vote is for it to do nothing. Returning a rejected Promise doesn't tell the page anything useful.

OK, so to sum it up:
* `navigator.wakeLock.request()` creates a `WakeLockSentinel` that can be `release()`d and which can receive up to 1 "release" event.
* An event like a page visibility change causes existing `WakeLockSentinel`s' `release()` methods to silently do nothing, and all these objects receive up to 1 "release" event
* Otherwise, calling `WakeLockSentinel.release()` works once and delivers up to 1 "release" event to the same object.

If that's the case:
* A `WakeLockEvent`'s only attribute is `lock`, which is a `WakeLockSentinel`. If we've reached a "release" event handler with a `WakeLockEvent`, calling `release()` on it will either do nothing or return a rejected promise based on the above. In other words `lock` is essentially useless in a `WakeLockEvent` except for its `type` attribute. In this case, wouldn't it suffice to have a `type` attribute in `WakeLockEvent` to do something like
    lock.addEventListener('release', ev => { lock = navigator.wakeLock.request(ev.type); })
* Is the "release" event supposed to indicate that a particular `WakeLockSentinel` has been released or that the platform wake lock has been released? In other words, if I create two screen wake locks and call `release()` on one, should it instantly receive a "release" event or does that happen only when both locks are released and we thus no longer hold a platform wake lock?

GitHub Notification of comment by rakuco
Please view or discuss this issue at https://github.com/w3c/wake-lock/issues/226#issuecomment-538391442 using your GitHub account
Received on Friday, 4 October 2019 13:13:54 UTC

This archive was generated by hypermail 2.4.0 : Monday, 4 July 2022 12:47:57 UTC