You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a12ba5a
Browse filesBrowse the repository at this point in the historyBrowse files
feat: Use AbortSignal in typescript, add a native timeout capability 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>
0 commit comments