Skip to content

@nodelibraries/enhanced-abort-controllerEnhanced AbortController

Enhanced AbortController with Node.js-style patterns for modern TypeScript applications. Clean, fully type-safe with zero external libraries. Built on top of the native Web API AbortController.

Quick Start โ€‹

bash
npm install @nodelibraries/enhanced-abort-controller
typescript
import { EnhancedAbortController } from '@nodelibraries/enhanced-abort-controller';

const controller = new EnhancedAbortController();
controller.abortAfter(5000); // Abort after 5 seconds

// Use with fetch
fetch('https://api.example.com/data', {
  signal: controller.signal.signal,
}).catch((err) => {
  if (err.name === 'AbortError') {
    console.log('Request was cancelled');
  }
});

Why @nodelibraries/enhanced-abort-controller? โ€‹

@nodelibraries/enhanced-abort-controller is an enhanced version of the native AbortController with additional features for modern Node.js and TypeScript applications. It provides timeout-based cancellation, linked controllers, and proper resource cleanup patterns.

Learn more about our features and design principles in the Introduction guide.

๐ŸŽฏ Clean & Simple โ€‹

No decorators, no annotations, no framework lock-in. Your code remains pure and framework-agnostic.

typescript
// Clean, simple usage
const controller = new EnhancedAbortController();
controller.abortAfter(5000); // Auto-abort after 5 seconds

๐Ÿ”’ Type-Safe by Design โ€‹

Built from the ground up for TypeScript. Full type inference, autocomplete, and compile-time safety.

typescript
// Full type safety with autocomplete
const controller = new EnhancedAbortController();
controller.signal.throwIfAborted(); // โœ… TypeScript knows this method exists

๐Ÿš€ Production Ready โ€‹

Battle-tested features including timeout management, linked controllers, and comprehensive error handling.

typescript
// Linked controllers for complex scenarios
const userController = new EnhancedAbortController();
const timeoutController = EnhancedAbortController.timeout(10000);

// Abort if user cancels OR timeout occurs
const linked = EnhancedAbortController.linkSignals(
  userController.signal,
  timeoutController.signal
);

๐Ÿ”„ Enhanced Features โ€‹

Additional features beyond the native AbortController:

  • Timeout Support - Automatic timeout-based cancellation
  • Linked Controllers - Combine multiple abort signals
  • TimeSpan - Precise time interval management
  • Resource Cleanup - Automatic cleanup callbacks
  • Promise Support - whenAborted promise for async workflows

๐ŸŽจ Flexible Usage โ€‹

Use with:

  • Native fetch API - Direct integration with fetch
  • Axios - Works seamlessly with Axios
  • Custom async operations - Any async operation that supports AbortSignal
  • Resource management - Automatic cleanup patterns

Installation โ€‹

bash
npm install @nodelibraries/enhanced-abort-controller

No additional configuration required! The library has zero dependencies and works out of the box.

Next Steps โ€‹

Released under the MIT License. If you find this project helpful, consider buying me a coffee โ˜•