Re: [whatwg/dom] AbortController.prototype.timeout and AbortController.prototype.cancel (Issue #1039)

I agree about the `.cancel()` name potentially being confusing. It also doesn't help that Streams already has `readableStream.cancel()` and `writableStream.abort()`. 😅 Perhaps `abortController.close()` is better? 🤔 

The proposed `.timeout()` method seems quite complex, and I'm not sure if it's sufficiently general to be worth adding to the platform. I think it'd be better if we could first add some more "fundamental" utilities such as `abortController.follow()` (#920) and `abortController.close()`, on top of which you can build `.timeout()`:

```javascript
class TimeoutAbortController extends AbortController {
  #timer;

  timeout(delay) {
    if (this.#timer) {
      this.#timer.close(); // assuming this also cleans up the followed AbortSignal.timeout() signal
    }
    this.#timer = new AbortController();
    this.#timer.follow(AbortSignal.timeout(delay));
    this.follow(this.#timer.signal);
  }
}
```

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

Received on Monday, 6 December 2021 18:50:22 UTC