Skip to content

feat: add AbortController/AbortSignal support for request cancellation#150

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/add-abort-cancel-request-feature
Closed

feat: add AbortController/AbortSignal support for request cancellation#150
Copilot wants to merge 2 commits intomasterfrom
copilot/add-abort-cancel-request-feature

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

No way to cancel an in-flight translation request — once initiated, it runs to completion or timeout.

Changes

  • Options interface — adds signal?: AbortSignal field
  • translate() — forwards signal to the axios request config (axios ≥1.x supports AbortSignal natively)
  • Tests — covers pre-aborted signal, mid-flight abort, and clean pass-through of a non-aborted signal

Usage

const controller = new AbortController();

const promise = googletrans("hello", { to: "zh", signal: controller.signal });

controller.abort(); // cancel at any time

await promise; // rejects with CanceledError

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • registry.npmmirror.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/npm install (dns block)
  • translate.google.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/googletrans/googletrans/node_modules/jest-worker/build/workers/processChild.js (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node node_modules/jest/bin/jest.js --config jestconfig.json --testNamePattern=AbortController --runInBand (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature request] add ability to abort/cancel/terminate the request mid-way</issue_title>
<issue_description>axios has supports for AbortController to terminate a request at any time.

googletrans doesn't have this in the options paramater and i would really appreciate it if you can add this as a new feature</issue_description>

Comments on the Issue (you are @copilot in this section)


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

Copilot AI changed the title [WIP] Add ability to abort or cancel request in googletrans feat: add AbortController/AbortSignal support for request cancellation Mar 26, 2026
Copilot AI requested a review from DarinRowe March 26, 2026 10:43
@DarinRowe DarinRowe requested review from Copilot and removed request for DarinRowe March 26, 2026 11:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds AbortController/AbortSignal-based cancellation support to in-flight translation requests by threading an optional abort signal through the public options and into the underlying axios request.

Changes:

  • Extend Options with signal?: AbortSignal.
  • Forward signal into the axios request config in translate().
  • Add Jest coverage for pre-aborted, non-aborted, and aborted requests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/googletrans.ts Extends the translation options and passes the abort signal through to axios for request cancellation.
src/__tests__/test.ts Adds new tests intended to verify AbortController/AbortSignal behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/__tests__/test.ts
Comment thread src/__tests__/test.ts
@DarinRowe DarinRowe marked this pull request as ready for review March 26, 2026 11:26
@DarinRowe
Copy link
Copy Markdown
Owner

Closing in favor of #151, which now contains the reviewed AbortController support plus stronger deterministic test coverage.

@DarinRowe DarinRowe closed this Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] add ability to abort/cancel/terminate the request mid-way

3 participants