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

partial-promises

v1.0.3

Published

Cancel reject/pending promises after a timeout. You pass an array of promises, if some of them stay in pending or reject, `partial-promises` cancels those promises and returns only those that will resolve within a timeout.

Downloads

25

Readme

partial-promises

Cancel reject/pending promises after a timeout. You pass an array of promises, if some of them stay in pending or reject, partial-promises cancels those promises and returns only those that will resolve within a timeout.

Installation & Usage

  $> npm install partial-promises

  (or)

  $> yarn add partial-promises
import { getPartialPromises, getPartialResults } from "partial-promises";

// or

const pp = require("partial-promises");
const promises = [
  createResolvePromise(1000), // Promise that resolves at 1sec with 1000
  createRejectPromise(2000), // Promise that rejects
  createResolvePromise(3000), // Promise that resolves at 3sec with 3000
  createResolvePromise(4000), // Promise that resolves at 4sec with 4000
  createResolvePromise(5000), // Promise that resolves at 5sec with 5000. We don't want to wait 5sec. Out limit is 4sec
];

const p = pp.getPartialPromises(promises, { time: 4000, resolveWith: "hello" });
Promise.all(p).then(d => console.log(d)); // [1000, "hello", 3000, 4000, "hello"]

const pr = pp.getPartialResults(promises, { time: 4000 });
pr.then(a => console.log(a)); // [1000, 3000, 4000]

Check test/index.test.ts for more usage examples.

API

1. getPartialPromises(promises[, options])

Returns array of promises that will always resolve, either with their actual value or options.resolveWith value

  • promises - array of promises
  • options
    • time
      • time in msec after getPartialPromises returns whatever promises resolved till then.
      • default is 2000
    • resolveWith
      • value to be replaced for rejected and timed out
      • default is 1

Note:

After using getPartialPromises(), returned promises can be filtered and take resolved and discard promises with resolveWith value.

// Example:

const promises = [
  resolvePromise(1000), // resolves after 1 sec and returns 1000
  rejectPromise(2000), // rejects after 2 sec
  resolvePromise(3000),
  resolvePromise(4000),
  resolvePromise(5000),
];

const p = await getPartialPromises(promises, {
  time: 3000,
  resolveWith: 1,
});

const results = await Promise.all(p);
// results = [1000, 1, 3000]

const resolved = results.filter(a => a !== 1); // 1 is resolveWith value
// resolved = [1000, 3000]

2. getPartialResults(promises[, options])

Same as getPartialPromises but intead of returning array of promises, returns array of resolved values, optionally filters out resolveWith values out-of-the-box

  • promises - array of promises
  • options
    • time
      • time in msec after getPartialResults returns whatever promises resolved till then.
      • default is 2000
    • resolveWith
      • value to be replaced for rejected and timed out
      • default is 1
    • filter
      • filters out results that are same as resolveWith
      • default is false
const promises = [
  resolvePromise(1000), // resolves after 1 sec and returns 1000
  rejectPromise(2000), // rejects after 2 sec
  resolvePromise(3000),
  resolvePromise(4000),
  resolvePromise(5000),
];

const p = await getPartialResults(promises, { time: 3000 });
// [1000, 3000]
// See ? You don't have to use Promise.all(p) & filter again like in getPartialPromises

// You can choose to not filter automatically so that you want to filter later.

const q = await getPartialResults(promises, {
  time: 3000,
  filter: false,
  resolveWith: -1, // default is 1
});
// [1000, -1, 3000] no filtering of -1 which is result of rejected promise

License

MIT © Sai Sandeep Vaddi