Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 1.16 KB

README.md

File metadata and controls

26 lines (17 loc) · 1.16 KB

better-promise-hash npm 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!