- From: M.K. <notifications@github.com>
- Date: Mon, 10 Jun 2024 22:23:37 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/1112/2159818221@github.com>
Over in the thread where I originally became confused, I found a solution for the case there, that also may work more generally. I was mislead by some assumptions made in that other thread, and the thread title here, but actually the current spec isn't really evil, just very confusing by omission. The requirement > Any web platform API using promises to represent operations that can be aborted must adhere to the following: > • Accept [AbortSignal](https://dom.spec.whatwg.org/#abortsignal) objects through a signal dictionary member. > — [DOM spec, chapter 3.3 "Using AbortController and AbortSignal objects in APIs"](https://dom.spec.whatwg.org/#abortcontroller-api-integration) in itself is somewhat useful, because then in scenarios where the only one type of signal is plausible, you can write nifty code like this: ```javascript async function getExampleWebsite() { const { abort, signal } = new AbortController(); return fetch('https://www.example.net/', { signal }).then(resp => resp.text()); } ``` And it does in fact not impede on good API design, because we can still use descriptive property names as the default and recommendation in our config objects, we just have to additionally accept AbortSignal on the generic name. It allows to interpret whatever is given in the genericly named property based on its type. In the original example that started this thread, the API could indeed offer the desired abortSignal option alongside the existing auctionSignals, sellerSignals, and perBuyerSignals. It could take inspiration from the type-aware interpretation so that if signal is set to a SellerSignal, it would be appended to the list of sellerSignals etc. Assuming the existing options have the empty list as default, this could allow for similarly concise code ```javascript const { initialBid, signal } = watchSeller(name); const bot = new FledgeApiClient({ signal }); ``` -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/1112#issuecomment-2159818221 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/dom/issues/1112/2159818221@github.com>
Received on Tuesday, 11 June 2024 05:23:41 UTC