Skip to content

feat: Add Abort Controller - #40

Merged
AryanSharma48 merged 3 commits into
AryanSharma48:mainfrom
Tejas-Narula:main
Sep 1, 2026
Merged

feat: Add Abort Controller#40
AryanSharma48 merged 3 commits into
AryanSharma48:mainfrom
Tejas-Narula:main

Conversation

@Tejas-Narula

Copy link
Copy Markdown
Contributor

Description

Feature: Added native AbortController support.
Fix: Cancelling a request now immediately interrupts any ongoing backoff delay (sleep), preventing the app from hanging.
Logic: Added pre-flight abort checks before network requests and preserved the original AbortError objects when throwing.
Testing & Docs: Added a dedicated test suite (abort.test.ts) and updated the TypeScript package's README.md with usage examples.

Fixes #5 (issue number)

Type of Change

Please check the option that applies:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation/Website update (changes to READMEs, examples, inline comments, or the documentation website)

Checklist

Design & Parity

  • If this introduces a new configuration option or public API, I have implemented equivalent options/behavior in both TypeScript and Python packages.
  • The core packages remain dependency-free (no new external runtime dependencies added).
  • I have updated the relevant package-specific README.md or general documentation where necessary.
  • If applicable, I have updated the examples or website to reflect these changes.

Quality & Testing

  • I started the sandbox Express server (cd sandbox && npm install && npm start) in a separate terminal before running the tests.
  • TypeScript Package: I have run the TypeScript tests (npm install && npm run build && npm test inside packages/smooth-api-ts) and all tests passed.
  • Python Package: I have run the Python tests (pip install -e ".[dev]" && pytest inside packages/smooth-api-py) and all tests passed.
  • I have added new tests to cover my changes.
  • I have commented my code, particularly in hard-to-understand areas, and updated JSDoc/docstrings.

@github-actions

Copy link
Copy Markdown

Hi there! Thanks for your first pull request! We'll review it shortly.

While it's getting reviewed, feel free to join our Discord community for suggestions and chat.

return new Promise(resolve => setTimeout(resolve, ms));
export function sleep(ms: number, signal?: AbortSignal | null): Promise<void> {
return new Promise((resolve, reject) => {
if (signal?.aborted) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small edge case: if signal.reason is undefined (which can happen in older environments or if aborted without a specific reason), falling back to a standard Error means err.name will just be 'Error'.

In the README.md, you suggest users check if (err.name === 'AbortError'), which would fail for this fallback case. Similarly in the call in src/index.ts

breaker.recordSuccess(domain);
return response;
} catch (err) {
lastError = err;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the actual fetch() call throws an AbortError?

We need to make sure this catch block doesn't swallow the cancellation and accidentally retry the aborted request.

@AryanSharma48 AryanSharma48 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicks for certain edge cases, otherwise great implementation!

Updated error handling in sleep function to throw DOMException with 'AbortError' name when aborted.
Updated error handling for abort scenarios to match native fetch behavior.
@AryanSharma48
AryanSharma48 merged commit fe983d1 into AryanSharma48:main Sep 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation First-Time Contributor packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add AbortController Integration

2 participants