Conversation
Co-authored-by: DarinRowe <5706314+DarinRowe@users.noreply.github.com> Agent-Logs-Url: https://github.com/DarinRowe/googletrans/sessions/a33ec70d-5a93-4fe7-afe0-dab7ec7f58f8
Copilot
AI
changed the title
[WIP] Add ability to abort translation requests using AbortController
feat: add AbortController/signal support to cancel in-flight translation requests
Mar 26, 2026
There was a problem hiding this comment.
Pull request overview
Adds first-class request cancellation support by threading an AbortSignal through the library’s translation request path (axios), plus documentation and a test to validate cancellation behavior.
Changes:
- Extended the public
Optionsinterface withsignal?: AbortSignal. - Forwarded
signalinto the axios request config so callers can cancel in-flight requests viaAbortController. - Documented the new option in the README and added a Jest test covering abort/cancel behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/googletrans.ts |
Adds signal to Options and passes it to axios to enable cancellation. |
src/__tests__/test.ts |
Adds an abort/cancel test for the new signal option. |
README.md |
Documents signal and provides a cancellation usage example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
AbortSignalsupport to theOptionsinterface so callers can cancel in-flight translation requests via the standardAbortControllerAPI, which axios already supports natively.Changes
src/googletrans.ts— Addedsignal?: AbortSignaltoOptions; forwarded it to the axios request configREADME.md— Documented thesignaloption with a usage examplesrc/__tests__/test.ts— Added a test asserting that aborting before resolution rejects with a cancellation errorUsage
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/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/npm install(dns block)/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/_temp/ghcca-node/node/bin/npm ci(dns block)translate.google.com/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)/home/REDACTED/work/_temp/ghcca-node/node/bin/node node node_modules/jest/bin/jest.js --config jestconfig.json --testPathPattern=test.ts --testNamePattern=(AbortController|getCode|getToken|random|getUserAgent|getReslut|Security|Additional Branch|test-helpers)(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Feature Request
Implements issue #148: Add the ability to abort/cancel/terminate a translation request mid-way using the standard
AbortController/AbortSignalAPI, which axios natively supports.Changes Required
1.
src/googletrans.tsExtend the
Optionsinterface to include an optionalsignalfield:Pass
signalto the axios call inside thetranslate()function (around line 154):Make sure
signalis extracted and handled properly from_optsso it doesn't interfere with other option processing (e.g., it should not be passed togetCode,getSafeTld, etc.).2.
README.mdAdd a documentation section explaining how to use the new
signaloption withAbortController. Example:3. Tests (optional but encouraged)
If there are existing test files in
src/__tests__/, add a test case that:AbortControllergoogletrans()with thesignalcontroller.abort()Acceptance Criteria
Optionsinterface includessignal?: AbortSignalsignalis passed to the axios request configcontroller.abort()causes the in-flight request to be cancelledsignaloption with a usage exampleThe following is the prior conversation context from the user's chat exploration (may be truncated):
User: can you do it?
Assistant: I can see you're referencing this GitHub issue: #148
Let me fetch the details of that issue first!
Assistant: Here's a summary of the issue:
[Feature request] Add ability to abort/cancel/terminate the request mid-way
DarinRowe/googletrans#148AbortControllerin the options parameter, so users can cancel/terminate an in-flight translation request mid-way — similar to howaxiosnatively supports it.Would you like me to create a pull request to implement this feature (i.e., add
AbortController/signalsupport to thegoogletransoptions)? If so, I can get started on that right away!User: 可以实现吗
Assistant: Let me look at the repository code to understand the current implementation before determining feasibility.
Assistant: 完全可以实现!✅
我仔细查看了源代码,以下是分析:
可行性分析
现有代码结构
src/googletrans.tsOptions接口只有from、to、tld、client四个字段实现方案
axios 原生支持
cancelToken和signal(AbortController),只需做以下修改:1. 扩展
Options接口,添加signal字段:2. 在
axios调用时传入signal:3. 用户使用示例:
改动量
Options接口translate()函数传入signalgoogletrans()入口函数兼容是否要我直接创建一个 Pull Request 来实现这个功能?🚀
User: do it
Assistant: We're waiting for your response to the tool call dialog to continue — please accept or reject it to proceed!
This pull request was created from Copilot chat.
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.