- From: Nicolas Stepien <notifications@github.com>
- Date: Mon, 23 Mar 2026 09:15:09 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/1461/4111846224@github.com>
nstepien left a comment (whatwg/dom#1461)
When trying out the exact example given in the spec: https://dom.spec.whatwg.org/#example-throwifaborted
```js
async function waitForCondition(func, targetValue, { signal } = {}) {
while (true) {
signal?.throwIfAborted();
const result = await func();
if (result === targetValue) {
return;
}
}
}
const signal = AbortSignal.timeout(500);
// ⚠️ this never aborts
waitForCondition(
async () => 1,
2,
{ signal }
);
// ⚠️ yielding to the main thread, never aborts
waitForCondition(
async () => {
await scheduler.yield();
return 1;
},
2,
{ signal }
);
// ⚠️ postTask with 'user-blocking' priority, never aborts
waitForCondition(
async () => {
await scheduler.postTask(() => {}, { priority: 'user-blocking', signal });
return 1;
},
2,
{ signal }
);
// ✅ postTask with 'user-visible' or 'background' priority, the loop aborts after timeout is reached!
waitForCondition(
async () => {
await scheduler.postTask(() => {}, { priority: 'user-visible', signal });
return 1;
},
2,
{ signal }
);
```
Not every scheduled tasks are created equal, so the `AbortSignal.timeout()` API is not good enough as it stands, in my honest opinion.
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1461#issuecomment-4111846224
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/dom/issues/1461/4111846224@github.com>
Received on Monday, 23 March 2026 16:15:13 UTC