Skip to content

shhQuiet/better-promise-hash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

A better implementation of a hash function for Promise

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published