Re: [whatwg] Notifications: making requestPermission() return a promise

From: Tab Atkins Jr. [mailto:jackalmage@gmail.com] 

> Again, if this means that the current design for "await" becomes less convenient, *we can fix await to work better*. It's not set in stone, it's not developed yet.  This is a thing we can change.

To be clear, this will not be happening. Await is designed very much to play well with promise semantics and to carry over the return value/thrown exception parallel even more directly than promises already do. As I said earlier, if you'd prefer some kind of Option type, perhaps with its own dedicated syntax, that's something you can try proposing. But await and promises are tied to exception semantics, have been since day 1, and are in all other languages which have similar constructs. Nobody on TC39 is planning to depart from that path, especially since async functions with these semantics have been proposed, in one form or another, since the early days of ES Harmony.

> But let's not twist our necks around and force promise APIs into an unnatural and inconvenient shape just because a naive translation to sync code produces errors and people find try/catch annoying or distasteful.

I disagree with your characterization of "unnatural and inconvenient", of course. An `if` statement is the most natural thing in the world.

What I find interesting here is the claim that people find try/catch annoying or distasteful. Why should they? It's the proper, syntactic way to handle errors---none of this "error" event business, or error-first callbacks, or even promise rejection callbacks. That's how exceptional, stack-unwinding errors that are meant to immediately halt execution should be contained and handled.

The question, again, is very simple. Is being denied permission an exceptional error that developers want to bubble to the outermost `catch (e) { ... }` block, or outermost `.catch(e => { ... })` handler? Or will they always want to deal with both paths of the result immediately? Tobie's argument about treating permissions as progressive enhancement is a good argument for the latter, IMO.

Received on Wednesday, 8 October 2014 16:07:58 UTC