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 🙏

© 2024 – Pkg Stats / Ryan Hefner

settle-all-promises

v2.1.1

Published

Utility to run multiple promises & deliver execution results of all Promises at a time.

Downloads

59

Readme

settle-all-promises

Utility to run multiple promises & deliver execution results of all Promises at a time.

An alternative to Promise.allSettled() method for versions of node prior to 12.9.0

Installation

npm i settle-all-promises --save

Use

var settle = require('settle-all-promises').settle;
var stat = require('settle-all-promises').stat;

var p0  = new Promise((resolve, reject) => {
    resolve('p0 result')
});

var p1  = new Promise((resolve, reject) => {
    resolve({'message' : 'p1 result message'})
});

var p2  = new Promise((resolve, reject) => {
    reject('p2')
});

settle([p0, p1, p2]).then(results => {
    // p0 result at index 0
    console.log('p0 isResolved() ' + results[0].isResolved);
    console.log(results[0].resultData);

    // p1 result at index 1
    console.log('p1 isResolved() ' + results[1].isResolved);
    console.log(JSON.stringify(results[1].resultData));

    // p2 result at index 2
    console.log('p2 isResolved() ' + results[2].isResolved);
    console.log('p2 isRejected() ' + results[2].isRejected);
    console.log(results[2]);

    // Print statistics of execution
    console.log(JSON.stringify(stat(results)));
})

Output

p0 isResolved() true
p0 result
p1 isResolved() true
{"message":"p1 result message"}
p2 isResolved() false
p2 isRejected() true
PromiseResult {
  _original: Promise { <rejected> 'p2' },
  _resultData: null,
  _errorData: 'p2'
}
{"resolvedCount":2,"rejectedCount":1}

Note

Use of arrow OR Lambda function syntax may not be allowed in older node versions prior to 4.2.4 use normal function callbacks syntax instead. Take look at examples below,

// 1. Using arrow function AKA Lambda function, for node versions
// after or equal to 4.0.0
settle([p0, p1, p2]).then(results => {
   // Process results here
});

// 2. Using normal function callback, for node versions
// before 4.0.0
settle([p0, p1, p2]).then(function(results) {
   // Process results here
});

// 3. Using async-await, for node versions
// after or equal to 7.6.0
async function callSettle() {
  const results = await settle([p0, p1, p2]);
  // Process results here
}

For additional examples checkout the test/index.test.ts file.

Compatibility

Min node version tested against -> v0.12.0 Max node version tested against -> v14.3.0