StarlingMonkey icon indicating copy to clipboard operation
StarlingMonkey copied to clipboard

Implement AbortConrtoller and AbortSignal

Open andreiltd opened this issue 9 months ago • 0 comments

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

andreiltd avatar Apr 18 '25 10:04 andreiltd