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

@tnr/smart-promise

v0.0.3

Published

Smart promise supports pool and concurrency limits

Readme

SmartPromise

A Promise extension with built-in concurrency control for JavaScript/TypeScript.

Installation

npm install @tnr/smart-promise
# or
yarn add @tnr/smart-promise

Features

  • 🚀 Drop-in replacement for native Promise
  • 🎛️ Concurrency control - limit simultaneous promise execution
  • 🔄 Automatic queuing - pending promises wait for available slots
  • 📦 Multiple execution modes - concurrent and sequential with delay
  • 💪 TypeScript support - full type safety included
  • 🪶 Lightweight - minimal overhead over native Promises

Quick Start

import SmartPromise from "@tnr/smart-promise";

// Limit concurrent database calls to 5
const users = await SmartPromise.all(
  userIds.map((id) => () => fetchUser(id)),
  { concurrency: 5 }
);

// Handle mixed success/failure with concurrency control
const results = await SmartPromise.allSettled(
  urls.map((url) => () => fetch(url)),
  { concurrency: 3 }
);

// Execute promises one by one
const ordered = await SmartPromise.sequential(
  tasks.map((task) => () => processTask(task))
);

API

SmartPromise.all(promises, options?)

Execute promises with concurrency control, similar to Promise.all().

const results = await SmartPromise.all(
  [task1, task2, task3, task4],
  { concurrency: 2 } // Max 2 concurrent
);

SmartPromise.allSettled(promises, options?)

Execute promises with concurrency control, similar to Promise.allSettled().

const results = await SmartPromise.allSettled([task1, task2, task3], {
  concurrency: 2,
});

SmartPromise.sequential(promises, options?)

Execute promises one by one in order.

const results = await SmartPromise.sequential(
  [task1, task2, task3],
  { delay: 100 } // Optional delay between tasks
);

SmartPromise.setDefaultConcurrency(limit)

Set default concurrency for all operations.

SmartPromise.setDefaultConcurrency(5);

// Now all operations use concurrency: 5 by default
await SmartPromise.all(tasks);

Promise Types

SmartPromise accepts both promise instances and promise factory functions:

// Promise instances (start immediately)
const promises = [fetch("/api/1"), fetch("/api/2"), fetch("/api/3")];

// Promise factories (start when called)
const factories = [
  () => fetch("/api/1"),
  () => fetch("/api/2"),
  () => fetch("/api/3"),
];

// Both work with concurrency control
await SmartPromise.all(promises, { concurrency: 2 });
await SmartPromise.all(factories, { concurrency: 2 });

Real-world Examples

Database Operations

// Batch process users without overwhelming the database
const users = await SmartPromise.all(
  userIds.map((id) => () => db.users.findById(id)),
  { concurrency: 10 }
);

API Rate Limiting

// Respect API rate limits
const responses = await SmartPromise.all(
  urls.map((url) => () => fetch(url)),
  { concurrency: 5 }
);

File Processing

// Process files without exhausting system resources
const processed = await SmartPromise.allSettled(
  files.map((file) => () => processFile(file)),
  { concurrency: 3 }
);

License

MIT

Contributing

Pull requests welcome! Please ensure tests pass with yarn test.