W3C home > Mailing lists > Public > public-device-apis-log@w3.org > December 2018

[wake-lock] Consider using the platform's standard cancelation primitive, AbortSignal (#142)

From: Domenic Denicola via GitHub <sysbot+gh@w3.org>
Date: Thu, 20 Dec 2018 19:48:40 +0000
To: public-device-apis-log@w3.org
Message-ID: <issues.opened-393187856-1545335319-sysbot+gh@w3.org>
domenic has just created a new issue for https://github.com/w3c/wake-lock:

== Consider using the platform's standard cancelation primitive, AbortSignal ==
Instead of a bespoke cancelable-request primitive with `WakeLockRequest`, instead use the `AbortSignal` primitive:

const signal = new AbortSignal();
wakeLock.createRequest({ signal });

// ... later ...

Although this may seem like slightly more typing, it has benefits of not inventing a bespoke new cancelation framework for people to learn, and also allows integration with other cancelable things on the platform. For example, a common pattern we're starting to see is that people want to cancel a bunch of things at once, using a single abort signal. Something like:

const signal = new AbortSignal();
(await navigator.getWakeLock("screen")).createRequest({ signal });
(await navigator.getWakeLock("system")).createRequest({ signal });

const res = await fetch("https://example.com/", { signal });
// ...

cancelButton.onclick = () => signal.abort();

Please view or discuss this issue at https://github.com/w3c/wake-lock/issues/142 using your GitHub account
Received on Thursday, 20 December 2018 19:48:41 UTC

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