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

@philiprehberger/retry-queue

v0.2.0

Published

Retry queue with exponential backoff for resilient async processing

Downloads

332

Readme

@philiprehberger/retry-queue

CI npm version Last updated

Retry queue with exponential backoff for resilient async processing.

Installation

npm install @philiprehberger/retry-queue

Usage

import { createQueue } from '@philiprehberger/retry-queue';

const queue = createQueue<{ url: string; body: string }>({
  process: async (item) => {
    const res = await fetch(item.url, { method: 'POST', body: item.body });
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
  },
  maxRetries: 5,
  retryDelay: 1000,
  onSuccess: (item) => console.log(`Sent: ${item.url}`),
  onFailure: (item, error) => console.error(`Failed: ${item.url}`, error),
  onRetry: (item, attempt) => console.log(`Retry ${attempt}: ${item.url}`),
});

queue.add({ url: '/api/events', body: JSON.stringify({ event: 'click' }) });

// Pause during offline
window.addEventListener('offline', () => queue.pause());
window.addEventListener('online', () => queue.resume());

Dead Letter Queue

Items that exceed maxRetries are automatically moved to a dead letter queue for later inspection or reprocessing.

const queue = createQueue<string>({
  process: async (item) => { throw new Error('always fails'); },
  maxRetries: 3,
  retryDelay: 100,
});

queue.add('will-fail');

// Later, inspect permanently failed items
const deadItems = queue.getDeadLetterItems();
for (const entry of deadItems) {
  console.log(entry.item, entry.error.message, entry.attempts, entry.failedAt);
}

// Clear when done
queue.clearDeadLetterQueue();

Jitter in Exponential Backoff

Add jitter to backoff delays to avoid thundering herd problems when many clients retry simultaneously.

// Full jitter: delay is random between 0 and the calculated backoff
const queue = createQueue<string>({
  process: async (item) => { /* ... */ },
  retryDelay: 1000,
  jitter: 'full',
});

// Decorrelated jitter: delay is random between baseDelay and backoff * 3
const queue2 = createQueue<string>({
  process: async (item) => { /* ... */ },
  retryDelay: 1000,
  jitter: 'decorrelated',
});

Max Queue Length

Limit the number of items in the queue to prevent unbounded memory growth. Choose an overflow strategy for when the queue is full.

// Reject new items when the queue is full (default)
const queue = createQueue<string>({
  process: async (item) => { /* ... */ },
  maxQueueLength: 100,
  overflowStrategy: 'reject-new',
});

const accepted = queue.add('item'); // returns false if queue is full

// Drop the oldest item to make room for new ones
const queue2 = createQueue<string>({
  process: async (item) => { /* ... */ },
  maxQueueLength: 100,
  overflowStrategy: 'drop-oldest',
});

Item Timeout

Set a maximum age for items so they don't retry forever. Timed-out items are moved to the dead letter queue.

const queue = createQueue<string>({
  process: async (item) => { /* ... */ },
  maxRetries: 10,
  retryDelay: 5000,
  itemTimeout: 30000, // 30 seconds max lifetime per item
  onTimeout: (item) => console.log(`Timed out: ${item}`),
});

API

createQueue<T>(options: QueueOptions<T>)

Creates a new retry queue.

QueueOptions<T>

  • process(item) — Async function to process each item
  • maxRetries? — Maximum retry attempts (default: 3)
  • retryDelay? — Base delay in ms for exponential backoff (default: 100)
  • jitter? — Jitter mode for backoff: 'none', 'full', or 'decorrelated' (default: 'none')
  • maxQueueLength? — Maximum number of items in the queue (default: unlimited)
  • overflowStrategy? — What to do when queue is full: 'reject-new' or 'drop-oldest' (default: 'reject-new')
  • itemTimeout? — Maximum age in ms before an item is considered timed out (default: unlimited)
  • onSuccess?(item) — Called after successful processing
  • onFailure?(item, error) — Called when all retries exhausted
  • onRetry?(item, attempt) — Called before each retry
  • onTimeout?(item) — Called when an item exceeds its timeout

Queue instance

  • add(item) — Add an item to the queue; returns false if rejected due to maxQueueLength
  • pause() — Pause processing
  • resume() — Resume processing
  • clear() — Remove all pending items
  • pending — Number of items waiting in the queue
  • getDeadLetterItems() — Returns a copy of all permanently failed items
  • clearDeadLetterQueue() — Clears the dead letter queue
  • deadLetterCount — Number of items in the dead letter queue

Development

npm install
npm run build
npm test

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT