Re: [whatwg/dom] `AbortSignal.timeout()` may not abort past the timeout (Issue #1461)

nstepien left a comment (whatwg/dom#1461)

I checked the behavior of equivalent APIs in Node.js, and the behavior is a little bit better:
```js
import { scheduler, setImmediate } from 'node:timers/promises';
import { styleText } from 'node:util';

async function runUntilTimeout(type, func) {
  console.time(type);

  const signal = AbortSignal.timeout(500);

  while (!signal.aborted) {
    try {
      await func(signal);
    } catch {
      console.log(styleText('red', 'error caught'));
      break;
    }
  }

  console.timeEnd(type);
}

// ✅ this aborts
await runUntilTimeout('yield', async () => {
  await scheduler.yield();
});

// ✅ this aborts
await runUntilTimeout('setImmediate', async () => {
  await setImmediate();
});

// ✅ setImmediate throws an error when the signal aborts
await runUntilTimeout('setImmediate with signal', async (signal) => {
  await setImmediate(undefined, { signal });
});

// ⚠️ this never aborts
await runUntilTimeout('queueMicrotask', async () => {
  await new Promise(queueMicrotask);
});
```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1461#issuecomment-4112338835
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1461/4112338835@github.com>

Received on Monday, 23 March 2026 17:23:45 UTC