better-promise-hash

1.0.3 • Public • Published

better-promise-hash travis status

A better implementation of a hash function for Promise. Returns a promise that is fulfilled when all the given promises have been fulfilled. Any rejection rejects the whole hash.

The object passed to hash will be returned with promises replaced with the promise result. Any non-promise objects will simply remain in the result.

Sometimes you feel like a nut, sometimes you don't

This modules adds a hash function to Promise. This allows you to do things like this:

let object= {
  one: new Promise((resolve,reject) => {
      resolve('somePromiseValue');
    }),
  two: 'someOtherValue'
};

Promise.hash(object).then((result) => {
  console.log(result.one); // echos "somePromiseValue"
  console.log(result.two); // echos "someOtherValue"
});

This is similar to RSVP.hash, which supports a mix of promises and non-promise objects.

Hope that helps!

Readme

Keywords

Package Sidebar

Install

npm i better-promise-hash

Weekly Downloads

1

Version

1.0.3

License

MIT

Last publish

Collaborators

  • shhquiet