What is the issue with the DOM Standard?
When running synchronous code, signal.aborted does not become true after the expected timeout, signal.throwIfAborted() does not throw either.
This can be an issue in, for example, testing frameworks and lead to tasks never aborting if synchronous work keeps running.
I'd like to write code like this, but it's impossible as it stands:
const signal = AbortSignal.timeout(500);
while (!signal.aborted) {
// perform work...
task(signal);
}
Repro code:
const signal = AbortSignal.timeout(500);
const start = Date.now();
const timeout = start + 5000;
signal.addEventListener('abort', () => {
console.log('signal aborted');
});
while (Date.now() < timeout) {
// this should throw after 500ms
signal.throwIfAborted();
}
console.error('this log should be unreachable');
console.log('signal.aborted:', signal.aborted);
console.log('elapsed:', Date.now() - start);
signal.throwIfAborted();
Result:

What is the issue with the DOM Standard?
When running synchronous code,
signal.aborteddoes not becometrueafter the expected timeout,signal.throwIfAborted()does not throw either.This can be an issue in, for example, testing frameworks and lead to tasks never aborting if synchronous work keeps running.
I'd like to write code like this, but it's impossible as it stands:
Repro code:
Result: