WICG / close-watcher

A web API proposal for watching for close requests (e.g. Esc, Android back button, ...)
https://html.spec.whatwg.org/multipage/interaction.html#close-requests-and-close-watchers
71 stars 5 forks source link

Integrate with AbortSignal #13

Closed domenic closed 2 years ago

domenic commented 2 years ago

Feedback from @annevk and @smaug---- is that you should be able to do something like this:

const controller = new AbortController();
const watcher = new CloseWatcher({ signal: controller.signal });

controller.abort();

which will work the same as

const watcher = new CloseWatcher();
watcher.destroy();

The advantage, of course, is for cases where you have a single AbortSignal tied to many different things, one of which might be a CloseWatcher.