whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.1k stars 2.66k forks source link

Make promise resolution easier to get right #8569

Open jyasskin opened 1 year ago

jyasskin commented 1 year ago

https://github.com/w3c/permissions/issues/393 points out that many uses of resolve a Promise incorrectly happen from in parallel and without a task source. For that matter, many uses of queue a task also happen without a task source. We could play whack-a-mole fixing this, or we could make it easier for spec authors to get it right.

Possible approaches:

domenic commented 1 year ago

I don't think there's anything special about promise resolution here, as opposed to any other manipulation of JavaScript/IDL objects. So I don't think anything here should be promise-specific.

In general I think "hope authors read" is the approach we've taken with the spec ecosystem so far. We're working in a programming language with solid constraints (e.g., arguments to algorithms must match their declarations; many operations are only used on a given type of value; some operations are only usable on some threads). Almost none of those constraints are enforced by our tooling; it's more of a dynamic or interpreted language than a statically-checked one. We could work on adding more static checking, similar to your "complain about incorrect text" proposal, but I haven't seen a lot of progress on that so far.

jyasskin commented 1 year ago

I think Promises are special because they're the platform's mechanism for communicating across threads, but they're not actually thread-safe, and that misleads authors.