Re: [whatwg/webidl] Introduce "mark as handled" for promises (PR #1090)

@domenic commented on this pull request.



>  </div>
 
-This phrase is useful when you wish to aggregate the results of multiple promises, and then produce
-another promise from them, in the same way that {{Promise/all()|Promise.all()}} functions for
-JavaScript code.
+<div algorithm>
+    To <dfn export lt="mark a promise as handled|mark as handled">mark as handled</dfn> a
+    <code><a interface>Promise</a>&lt;<var ignore>T</var>&gt;</code> |promise|, set
+    |promise|.\[[Promise]].\[[PromiseIsHandled]] to true.
+
+    <p class="note">This definition is useful for promises which you expect rejections to often be
+    ignored; it ensures such promises do not cause {{Window/unhandledrejection}} events. The most
+    common use case is for promise properties, which the web developer might or might not consult.
+    An example is the {{WritableStreamDefaultWriter/closed|writableStreamWriter.closed}} promise,
+    which is [=marked as handled=] immediately after it is [=rejected=].

So what I've found recently (in app history) is that it's actually simplest to just mark the promise as handled upon creation. What streams does is perhaps unnecessarily complicated, and I wonder if maybe I should remove this example or make it more vague.

The advantage of this is that you can centralize your "this promise is special" logic at creation time, instead of all the different places you reject it. So if anything maybe a "new already-handled promise" algorithm would be useful? But for now my instinct is to just expose the primitive, since so far use cases are pretty rare.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/pull/1090#discussion_r794725400
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/pull/1090/review/866477215@github.com>

Received on Friday, 28 January 2022 17:50:09 UTC