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

promise-ngine

v0.0.23

Published

A promise engine to resolve all promises in an object with control over concurrency and seriality, passing the result along the way.

Readme

Promise Ngine

A promise engine to resolve async objects with concurrency and serial resolution on demand passing the result along the way.

Quick example:

Promise.ngine({
     finalString: "",
     greetings: [
          new Promise.NgineKey((resolve, reject, result) => {
               result.finalString += "hello ";
               resolve(result.finalString);
          }).pos(0),
          new Promise.NgineKey((resolve, reject, result) => {
               result.finalString += "!";
               resolve(result.finalString);
          }).pos(2)
     ],
     world: new Promise.NgineKey((resolve, reject, result) => {
          result.finalString += "world ";
          resolve(result.finalString);
     }).pos(1),
})
.then(result => {
     console.log(result.finalString) // hello world !
})

How to use :

Without binding to global Promise object

const PromiseNgine = new (require('promise-ngine'))();

Binding to global Promise object

const PromiseNgine = new (require('promise-ngine'))(true);

All examples will use the method binding to global Promise object.

The engine exposes two methods :

1. Promise.ngine

A method resolving all ngine keys contained in an object or an array passing the result.

Promise.NgineKey

An engine key is constructed with a method taking three arguments as below :

 new Promise.NgineKey((resolve, reject, result) => {});

An engine key can be resolved calling the resolve method passing the result that will be mapped to the key's original position in the object. It can also be resolved returning a Promise.

The property pos on a engine key sets the position of the Promise in the chain. 0 being first position.

 new Promise.NgineKey((resolve, reject, result) => {}).pos(0);

Examples

Example with a pseudo sql call and a pseudo mongo call needing result from sql :

Promise.ngine({
      user: {
          infos: new Promise.NgineKey((resolve, reject, result) => { // call happens first
               return db.query('select * from users where [email protected]') // returns a Promise
          }).pos(0),
          orders: new Promise.NgineKey((resolve, reject, result) => { // call happens second
               orders.find({id_user: result.user.infos.id})
               .then(resolve) // calls the resolve method
               .catch(reject);
          }).pos(1)
     }
})
.then(result => {
     console.log(result) // { user: { infos : {}, orders : [] } }
})

To have the 'orders' promise access the result of the 'infos' promise, the integer passed to .pos method of the 'orders' promise must be higher than the one for the 'infos' promise.

Concurrency

At the same time, you might need other data that don't need anything from the 'orders' promise but needs data from the 'infos' promise. Therefore, it can run concurrently with the 'orders' promise. This can be achieved by passing the same position as the one passed to the 'orders' promise.

Example:

Promise.ngine({
      user: {
          infos: new Promise.NgineKey((resolve, reject, result) => {
               db.query('select * from users where [email protected]')
               .then(resolve)
               .catch(reject);
          }).pos(0),
          orders: new Promise.NgineKey((resolve, reject, result) => {
               orders.find({id_user: result.user.infos.id})
               .then(resolve)
               .catch(reject);
          }).pos(1),
          comments: new Promise.NgineKey((resolve, reject, result) => {
               comments.find({id_user: result.user.infos.id})
               .then(resolve)
               .catch(reject);
          }).pos(1)
     }
})
.then(result => {
     console.log(result) // { user: { infos : {}, orders : [], comments: [] } }
})

So every promise sharing the same position wherever it is in the object will run concurrently. Therefore if a promise relies on the result of another one, they must not share the same position.

Copying the original object

Useful if you want to reuse the original object.

let obj = {
     somePromise: new Promise.NgineKey((resolve, reject, result) => resolve(true)).pos(0)
};
Promise.ngine(obj, { copy: true })
.then(result => {
     assert(result !== obj); // true
})

Subobject

An engine key can return another Promise.ngine. The sub ngine will have its own chain.

Example:

Promise.ngine({
     greeting: 'hello ',
     somePromise: new Promise.NgineKey((resolve, reject, result) => {
          return Promise.ngine({
               foo: 'bar',
               greeting: new Promise.NgineKey((resolve, reject, subresult) => {
                    return resolve(result.greeting + 'world !');
               }).pos(0)
          });
     }).pos(0)
})
.then(result => {
     console.log(result) // { greeting : 'hello ', somePromise : { foo : 'bar', greeting : 'hello world !' } }
})

Result available as this

the resulting object is also available with this inside an ngine key. In order for it to work do not use fat arrows functions.

Example:

Promise.ngine({
     greeting: 'hello ',
     somePromise: new Promise.NgineKey(function(resolve, reject) {
          this.greeting += 'world !';
          resolve('foo');
     }).pos(0)
})
.then(result => {
     console.log(result) // { greeting : 'hello world !', somePromise : 'foo' }
})

It works with unlimited depth. It works with arrays (as first argument also).

2. Promise.mapAll

See https://www.npmjs.com/package/promise-to-object