# prefer-abort-signal-timeout πŸ“ Prefer `AbortSignal.timeout()` over manually aborting an `AbortController` with `setTimeout()`. πŸ’ΌπŸš« This rule is enabled in the βœ… `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). This rule is _disabled_ in the β˜‘οΈ `unopinionated` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). πŸ’‘ This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). `AbortSignal.timeout()` creates an `AbortSignal` that automatically aborts after a delay. It avoids the extra `AbortController` and manual timer setup. This rule only reports the simple adjacent-statement pattern where the controller is otherwise only used through `.signal`. Cases that inspect the abort reason or alias the signal are ignored, as `AbortSignal.timeout()` uses a timeout-specific reason. Dynamic delay expressions are assumed to already be valid `AbortSignal.timeout()` delays within the unclamped `setTimeout()` range. ## Examples ```js // ❌ const abortController = new AbortController(); setTimeout(() => abortController.abort(), 1000); await fetch(url, {signal: abortController.signal}); ``` ```js // βœ… const abortSignal = AbortSignal.timeout(1000); await fetch(url, {signal: abortSignal}); ``` Controllers with other behavior are intentionally ignored. ```js // βœ… const abortController = new AbortController(); setTimeout(() => abortController.abort(), 1000); button.addEventListener('click', () => abortController.abort()); await fetch(url, {signal: abortController.signal}); ```