Re: [whatwg/dom] Timeout AbortSignal (or AbortController) that gets input from the operation (Issue #1082)

How I think of this:

Our base primitive is `AbortController`, which gives full programmatic control over when to abort, and with what reason.

We then add helpers for common cases where we can achieve a lot of simplicity. So `AbortSignal.timeout()` compresses us from

```js
const controller = AbortController();
setTimeout(() => controller.abort(new DOMException("TimeoutError", "..."), ms);
return controller.signal;
```

to just `AbortSignal.timeout(ms)`.

The compression here would probably be something like:

```js
const controller = AbortController();
let timerId = setTimeout(() => controller.abort(new DOMException("TimeoutError", "..."), ms);
onUpdate(() => {
  clearTimeout(timerId);
  timerId = setTimeout(() => controller.abort(new DOMException("TimeoutError", "..."), ms);
});
return controller.signal;
```

to


```js
const { signal, reset } = createHelper(ms);
onUpdate(() => reset());
return signal;
```

I'm not sure this kind of compression is worth it, but maybe it is.

If it were added, I think it could be separate from any Fetch addition. I.e., any Fetch addition would probably build on top of such a helper, but not in a web-developer-visible way.

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

Message ID: <whatwg/dom/issues/1082/1134799028@github.com>

Received on Monday, 23 May 2022 15:10:52 UTC