StarlingMonkey
StarlingMonkey copied to clipboard
Implement AbortConrtoller and AbortSignal
This patch implements AbortController and AbortSignal as specified in the DOM spec.
AbortSignal is connected to fetch requests and can be used to cancel them. For example, the following code will now work as expected
const controller = new AbortController();
const signal = controller.signal;
const timeoutId = setTimeout(() => controller.abort(), 500);
let error;
try {
await fetch('https://http-me.glitch.me/wait=5000', { signal });
} catch (err) {
error = err;
} finally {
clearTimeout(timeoutId);
}
console.log(error.name); // prints 'AbortError'
Closes: https://github.com/bytecodealliance/StarlingMonkey/issues/154
Depends on: https://github.com/bytecodealliance/StarlingMonkey/pull/220