Bug 1753309 Comment 15 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

>> shows handling for both a timeout abort and an abort signal triggered explicitly.

> That is not what the example shows. As it says in the comments, the "AbortError" case is for cases like the user pressing the stop button, or the page navigating away, or...

**I "think" understand what the example shows** but ... I don't see how the user can trigger an abort using a stop button when using the signal returned from a `timeout()` - and further down your comment appear support this as "requires future work". 

Apologies if I am being very dim, but to spell it out in excruciating detail, this is your example, which looks like it can catch a `TimeoutError`, `AbortError` or something else. The fetch only takes the signal returned by `AbortSignal.timeout()`. How would the code get a handle to the controller in order call abort on this?

```
try {
  const res = await fetch(url, { signal: AbortSignal.timeout(10_000) });
  const result = await res.text();
  // ...
} catch (e) {
  if (e.name === "TimeoutError") {
    // It took more than 10 seconds to get the result!
  } else if (e.name === "AbortError") {
    // The fetch was explicitly aborted, e.g. by the user pressing the stop button!
  } else {
    // Something horrible went wrong, like a network error!
  }
}
```
But down the explainer appears to support this:

> Future work: this feature would benefit greatly from a solution for combining AbortSignals, so that people could have an operation that aborts on either a timeout or an explicit abort. For example, something like this:
> ```
> // NOT REAL CODE, YET:
> const controller = new AbortController();
> fetch(url, { signal: AbortSignal.all([AbortSignal.timeout(10_000), controller.signal]) });
> 
> abortButton.onclick = () => controller.abort();
> ```

That appears to indicate that you can't pass in multiple signals to abort on.
>> shows handling for both a timeout abort and an abort signal triggered explicitly.

> That is not what the example shows. As it says in the comments, the "AbortError" case is for cases like the user pressing the stop button, or the page navigating away, or...

**I understand that the example "shows" how you might catch the "AbortError" but I don't see how that can be triggered since you don't have the controller. Specifically,  `AbortSignal.timeout()` returns an `AbortSignal` and there is no way to get hold of the AbortController so you can call abort on that signal (from the stop button).

Further down your comment appear support this case "requires future work", because otherwise why would you need fetch to take multiple signals?

To spell it out in excruciating detail, this is your example, which looks like it can catch a `TimeoutError`, `AbortError` or something else. The fetch only takes the signal returned by `AbortSignal.timeout()`. How would the code get a handle to the controller in order call abort on this?

```
try {
  const res = await fetch(url, { signal: AbortSignal.timeout(10_000) });
  const result = await res.text();
  // ...
} catch (e) {
  if (e.name === "TimeoutError") {
    // It took more than 10 seconds to get the result!
  } else if (e.name === "AbortError") {
    // The fetch was explicitly aborted, e.g. by the user pressing the stop button!
  } else {
    // Something horrible went wrong, like a network error!
  }
}
```
And then you say.

> Future work: this feature would benefit greatly from a solution for combining AbortSignals, so that people could have an operation that aborts on either a timeout or an explicit abort. For example, something like this:
> ```
> // NOT REAL CODE, YET:
> const controller = new AbortController();
> fetch(url, { signal: AbortSignal.all([AbortSignal.timeout(10_000), controller.signal]) });
> 
> abortButton.onclick = () => controller.abort();
> ```

I hope this has explained my confusion enough that you can explain where I'm completely missing the point?

Back to Bug 1753309 Comment 15