npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gigaretry

v2.0.0

Published

Flexible, fail-safe retry mechanism with exponential backoff, logging, timeout, and optional child process execution.

Readme

gigaretry

Retry any function — HTTP, DB, async, sync — with ease.
Smart retries made simple. Now with child process isolation.

Buy Me a Coffee


🚀 Features

  • 🔁 Retry any sync or async function
  • 🔒 NEW: Child process isolation for better error handling
  • ⏱️ Custom delay with exponential backoff support
  • 🎯 Set max attempts and timeout limits
  • 📄 Optional logging
  • 🧠 Minimal code, maximal flexibility
  • 🛡️ Process isolation prevents memory leaks and crashes

📦 Installation

npm install gigaretry

✨ Usage

Basic Retry

const { retryOperation } = require('gigaretry');

let count = 0;
async function unreliableTask() {
  count++;
  if (count < 3) throw new Error("Temporary failure");
  return "Success!";
}

(async () => {
  const result = await retryOperation(unreliableTask, [], {
    attempts: 5,
    delay: 1000,
    log: true
  });
  console.log(result); // "Success!"
})();

Child Process Isolation

const { retryOperation } = require('gigaretry');
const axios = require('axios');

// Run in isolated child process - perfect for unreliable APIs
const userData = await retryOperation(
  async (userId) => {
    const response = await axios.get(`https://api.example.com/users/${userId}`);
    return response.data;
  },
  ['123'],
  {
    attempts: 5,
    delay: 1000,
    childProcess: true, // 🔒 Runs in isolated process
    exponential: true,  // 📈 Exponential backoff
    maxTimeout: 30000,  // 🕐 Max 30s delay
    log: true
  }
);

Exponential Backoff

// Delays: 1s → 2s → 4s → 8s → 16s (capped at maxTimeout)
const result = await retryOperation(flakyFunction, [], {
  attempts: 5,
  delay: 1000,
  exponential: true,
  maxTimeout: 10000 // Cap at 10 seconds
});

🔧 Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | attempts | Number | 3 | Maximum retry attempts | | delay | Number | 1000 | Delay between retries (in ms) | | exponential | Boolean | false | Use exponential backoff | | maxTimeout | Number | 10000 | Maximum delay when using exponential backoff | | childProcess | Boolean | false | NEW: Run function in isolated child process | | log | Boolean | false | Log retry attempts to the console |


🔒 Child Process Benefits

Running functions in child processes provides several advantages:

  • Memory Isolation: Prevents memory leaks from affecting your main process
  • Crash Protection: Function crashes won't bring down your main application
  • Resource Limits: Better control over resource usage per operation
  • Clean Environment: Each retry starts with a fresh process state

Perfect for:

  • Unreliable third-party APIs
  • Memory-intensive operations
  • Functions that might crash or hang
  • Operations requiring clean state between retries

🧪 Real-World Examples

Database Operations

const { retryOperation } = require('gigaretry');

// Retry database connection with exponential backoff
const dbResult = await retryOperation(
  async () => {
    const connection = await database.connect();
    return await connection.query('SELECT * FROM users');
  },
  [],
  {
    attempts: 5,
    delay: 500,
    exponential: true,
    log: true
  }
);

File Operations

// Retry file operations in child process
const fileData = await retryOperation(
  async (filePath) => {
    const fs = require('fs').promises;
    return await fs.readFile(filePath, 'utf8');
  },
  ['/path/to/important/file.txt'],
  {
    attempts: 3,
    delay: 1000,
    childProcess: true
  }
);

HTTP Requests with Complex Logic

const complexApiCall = await retryOperation(
  async (endpoint, payload) => {
    const axios = require('axios');
    
    // Complex authentication and request logic
    const authToken = await getAuthToken();
    const response = await axios.post(endpoint, payload, {
      headers: { Authorization: `Bearer ${authToken}` },
      timeout: 5000
    });
    
    if (response.status !== 200) {
      throw new Error(`API returned ${response.status}`);
    }
    
    return response.data;
  },
  ['https://api.example.com/complex', { data: 'important' }],
  {
    attempts: 8,
    delay: 2000,
    exponential: true,
    maxTimeout: 60000,
    childProcess: true, // Isolate this complex operation
    log: true
  }
);

✅ Testing

Tests are written using Jest and cover both regular and child process operations.

npm install
npm test

📁 Project Structure

.
├── src/
│   ├── index.js         // Core retry logic
│   └── childRetry.js    // Child process handler
├── test/
│   └── retry.test.js    // Jest tests
├── .npmignore
├── package.json
├── CHANGELOG.md
└── README.md

🔄 Migration from v1.x

gigaretry v2.0 is backward compatible. Existing code will work unchanged:

// v1.x code works exactly the same in v2.x
const result = await retryOperation(myFunction, [], {
  attempts: 3,
  delay: 1000,
  log: true
});

New features are opt-in:

// v2.x - Add new features as needed
const result = await retryOperation(myFunction, [], {
  attempts: 3,
  delay: 1000,
  log: true,
  childProcess: true,  // NEW: opt-in feature
  exponential: true    // NEW: opt-in feature
});

🙋‍♂️ About the Author

Hey, I'm Namit Sharma — a backend engineer who enjoys building tiny tools that solve big annoyances.

I built gigaretry because most retry modules are tied to HTTP or overly complex. I wanted something simple, universal, and robust. The new child process feature came from real-world experience with unreliable APIs that would occasionally crash entire applications.

If it helped you avoid a headache (or three), you can:

👉 Buy me a coffee — it keeps the side-project fire alive ☕


📜 License

Apache-2.0 © Namit Sharma