-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use AbortController/*Signal instead of cancelWatch(optional long id); #147
Comments
The signal should be added to the Example on how to add to the spec: https://wicg.github.io/geolocation-sensor/#dom-readoptions-signal |
This definitely makes sense for push (which I think we should just rename to write to be consistent with Web Bluetooth etc). This even allows us to get rid of the timeout: const controller = new AbortController();
const signal = controller.signal;
const message = {
records: [{ recordType: "text", data: 'Hello World' }]
};
navigator.nfc.write(message, {signal});
// timeout after 3 seconds
setTimeout(() => controller.abort(), 3000); |
I agree with getting rid of a separate |
It basically came out of the whole cancellable promises discussion. Don't expect anything like observables on the web platform for a long time.
|
But push was an NFC-specific term.
I'd prefer var controller = navigator.nfc.write(message, options);
setTimeout(() => controller.abort(), 3000); In some cases we cannot guarantee cancellation. What happens then? It is not specified for |
Well, not really, I am pretty sure that I came up with that due to the Android UX for peer to peer
That would be the same with |
As always @domenic 's comments would be useful |
Strong +1 to using AbortController. As @kenchris has said, it is not related to network operations, and it's just how you cancel async operations on the platform. I can understand how it can seem complex in isolation. But as with promises, streams, etc., reusing the same primitive everywhere has multiplicative effects throughout the platform. In particular, there's a common pattern of using a single AbortSignal for a bunch of ongoing operations, and then aborting them (with the corresponding AbortController) when e.g. the user presses cancel, or a single-page-app navigation occurs, or similar. So the minor extra complexity for an individual API leads to a large reduction in complexity when used with multiple APIs together. Right now AbortController is only used in Fetch and Web Locks to my knowledge. But we're soon going to be using it in Streams, a promise-returning version of setTimeout (whatwg/html#617), and probably other upcoming APIs like writable files. Being able to cancel all these things together using a single tool is the dream, just like today you can use a single tool (promises) for async operations.
A call to |
OK, we could do that. I see there is a polyfill in Node.js too. We could even use that in the Web of Things as well as a generic pattern.
Right. A bit unrelated, but I am sad to see Observables go down, as it was a powerful single tool to handle events, streams with possibility to filtering at source or on consumption. Whatever. It's more important to have a workable consensus than to not have the best one. |
https://developer.mozilla.org/en-US/docs/Web/API/AbortController
That is a much more modern way of doing this, but one that didn't exist when
cancelWatch
was added to the specThe text was updated successfully, but these errors were encountered: