feat: Use AbortSignal in typescript, add a native timeout capability in python.#2373
feat: Use AbortSignal in typescript, add a native timeout capability in python.#2373
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Your trial period has expired. To continue using this feature, please upgrade to a paid plan here or book a time to chat here. |
|
🌿 Preview your docs: https://boundary-preview-7298b2ec-8f25-4bb1-927e-dd5ec317214c.docs.buildwithfern.com |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Generated with ❤️ by ellipsis.dev |
|
🌿 Preview your docs: https://boundary-preview-1d0347d6-b2b6-4650-88fc-ae526c074ad0.docs.buildwithfern.com |
|
🌿 Preview your docs: https://boundary-preview-61eb48a8-2f9c-419f-a085-b698e15ebf41.docs.buildwithfern.com |
|
🌿 Preview your docs: https://boundary-preview-047481e0-832a-4f16-bf3d-7417d224f6bb.docs.buildwithfern.com |
|
🌿 Preview your docs: https://boundary-preview-fc59d7c4-6393-4f48-97b8-da118b31eb6e.docs.buildwithfern.com |
This is likely to be more compatible with LLM coding agents, since this is the naming convention pretty much all standard Node APIs abide by: fetch, fs.promises, child_process.spawn, setTimeout, addEventListener, Axios, Got (HTTP client), p-queue, Puppeteer. Node that use other conventions tend to be legacy or non-standard (e.g. axios used `cancelToken` before `signal: AbortSignal` was added to the standard library), although interestingly both the AWS and Azure SDKs do use `abortSignal: AbortSignal`. The other reason I think we had for `abortSignal: AbortSignal` instead of `signal: AbortSignal` was for cross-language ergonomics, but a cursory look at other SDKs (e.g. aws and azure) tells me that they prioritize using the most language-native convention available (e.g. `cancellationToken` in C#) and I know Vaibhav and I both agree that the Python protobuf API is one of the least ergonomic APIs in existence because of the cross-language inconsistency. Followup to #2357 and #2373 - many thanks to @trojanowski for being a super active and involved user and pushing us to have a more ergonomic API!
…in python. (#2373) ## Summary Modernizes the abort controller API documentation to use the AbortSignal pattern, aligning with web standards while improving developer experience. **Key Changes:** - **Renamed documentation**: "Abort Controllers" → "AbortSignals / Timeouts" to better reflect modern usage patterns - **Updated TypeScript API**: Changed from `abortController` parameter to `abortSignal` to align with web standards - **Added modern timeout pattern for TS**: Introduced `AbortSignal.timeout(5000)` for simple timeout scenarios - **Enhanced Python support**: Added `AbortController(timeout_ms=5000)` constructor for built-in timeouts - **Updated cross-references**: Fixed all internal links and redirects throughout documentation ## Code Examples ### Before (old AbortController pattern): ```typescript const controller = new AbortController() const result = await b.ExtractResume(text, { abortController: controller // Old parameter name }) ``` ### After (modern AbortSignal pattern): ```typescript // Simple timeout approach const result = await b.ExtractResume(text, { abortSignal: AbortSignal.timeout(5000) // Modern web standard }) // Manual control when needed const controller = new AbortController() const result = await b.ExtractResume(text, { abortSignal: controller.signal // Updated parameter name }) ``` ### Python Simplification: **Before (complex manual timeout):** ```python async def with_timeout(operation, timeout_seconds): controller = AbortController() async def run_with_timeout(): timeout_task = asyncio.create_task(asyncio.sleep(timeout_seconds)) operation_task = asyncio.create_task(operation(controller)) done, pending = await asyncio.wait( [timeout_task, operation_task], return_when=asyncio.FIRST_COMPLETED ) if timeout_task in done: controller.abort() raise TimeoutError(f"Operation timed out after {timeout_seconds}s") return operation_task.result() return await run_with_timeout() # Usage result = await with_timeout( lambda ctrl: b.ExtractData(input, baml_options={"abort_controller": ctrl}), 5 # 5 second timeout ) ``` **After (built-in timeout support):** ```python # Much simpler with built-in timeout controller = AbortController(timeout_ms=5000) # Automatic timeout result = await b.ExtractData(input, baml_options={"abort_controller": controller}) ``` ## Impact This refactor eliminates the need for complex `asyncio.wait()` and manual task management by moving timeout functionality directly into the API, making it much cleaner and less error-prone while following modern web standards. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This is likely to be more compatible with LLM coding agents, since this is the naming convention pretty much all standard Node APIs abide by: fetch, fs.promises, child_process.spawn, setTimeout, addEventListener, Axios, Got (HTTP client), p-queue, Puppeteer. Node that use other conventions tend to be legacy or non-standard (e.g. axios used `cancelToken` before `signal: AbortSignal` was added to the standard library), although interestingly both the AWS and Azure SDKs do use `abortSignal: AbortSignal`. The other reason I think we had for `abortSignal: AbortSignal` instead of `signal: AbortSignal` was for cross-language ergonomics, but a cursory look at other SDKs (e.g. aws and azure) tells me that they prioritize using the most language-native convention available (e.g. `cancellationToken` in C#) and I know Vaibhav and I both agree that the Python protobuf API is one of the least ergonomic APIs in existence because of the cross-language inconsistency. Followup to #2357 and #2373 - many thanks to @trojanowski for being a super active and involved user and pushing us to have a more ergonomic API!
This is likely to be more compatible with LLM coding agents, since this is the naming convention pretty much all standard Node APIs abide by: fetch, fs.promises, child_process.spawn, setTimeout, addEventListener, Axios, Got (HTTP client), p-queue, Puppeteer. Node that use other conventions tend to be legacy or non-standard (e.g. axios used `cancelToken` before `signal: AbortSignal` was added to the standard library), although interestingly both the AWS and Azure SDKs do use `abortSignal: AbortSignal`. The other reason I think we had for `abortSignal: AbortSignal` instead of `signal: AbortSignal` was for cross-language ergonomics, but a cursory look at other SDKs (e.g. aws and azure) tells me that they prioritize using the most language-native convention available (e.g. `cancellationToken` in C#) and I know Vaibhav and I both agree that the Python protobuf API is one of the least ergonomic APIs in existence because of the cross-language inconsistency. Followup to #2357 and #2373 - many thanks to @trojanowski for being a super active and involved user and pushing us to have a more ergonomic API!
Summary
Modernizes the abort controller API documentation to use the AbortSignal pattern, aligning with web standards while improving developer experience.
Key Changes:
abortControllerparameter toabortSignalto align with web standardsAbortSignal.timeout(5000)for simple timeout scenariosAbortController(timeout_ms=5000)constructor for built-in timeoutsCode Examples
Before (old AbortController pattern):
After (modern AbortSignal pattern):
Python Simplification:
Before (complex manual timeout):
After (built-in timeout support):
Impact
This refactor eliminates the need for complex
asyncio.wait()and manual task management by moving timeout functionality directly into the API, making it much cleaner and less error-prone while following modern web standards.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com