Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@fortify-ts/timeout

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fortify-ts/timeout

Timeout pattern for Fortify TS resilience library

latest
Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
29
190%
Maintainers
1
Weekly downloads
 
Created
Source

@fortify-ts/timeout

Timeout pattern for the Fortify-TS resilience library.

Installation

npm install @fortify-ts/timeout
# or
pnpm add @fortify-ts/timeout

Features

  • Default and Per-Operation Timeouts: Configure default with override capability
  • Abort Signal Integration: Proper cancellation support
  • Timeout Notifications: onTimeout callback

Usage

Basic Usage

import { Timeout } from '@fortify-ts/timeout';

const timeout = new Timeout<Response>({
  defaultTimeout: 5000, // 5 seconds
});

try {
  const result = await timeout.execute(async (signal) => {
    return fetch('/api/data', { signal });
  });
} catch (error) {
  if (error instanceof TimeoutError) {
    console.log('Request timed out');
  }
}

Per-Operation Timeout

// Use default timeout
await timeout.execute(operation);

// Override with specific timeout
await timeout.executeWithTimeout(operation, 10000); // 10 seconds

Configuration Options

const timeout = new Timeout<Response>({
  // Default timeout in milliseconds
  defaultTimeout: 5000,

  // Timeout notification
  onTimeout: (duration) => {
    console.log(`Operation timed out after ${duration}ms`);
  },

  // Optional logger
  logger: myLogger,
});

With External Signal

const controller = new AbortController();

// Both timeout and external signal can cancel
const result = await timeout.execute(
  async (signal) => fetch('/api/data', { signal }),
  controller.signal
);

// Cancel from external code
controller.abort();

Configuration Reference

OptionTypeDefaultDescription
defaultTimeoutnumber30000Default timeout (ms)
onTimeoutfunction-Timeout callback
loggerFortifyLogger-Optional logger

License

MIT

Keywords

resilience

FAQs

Package last updated on 23 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts