promise-from-hash / 1.0.0 last updated 7 months ago created on Apr 19th 2014

Install

npm install --save promise-from-hash

Clone

git clone git@github.com:mikach/promise-from-hash.git

dependencies

main es6-promise 0.1.2 MIT

maintainers

mikach

versions

1.0.0 7 months ago mikach
1 Downloads yesterday.

readme

Promise.all for hash

Quick example

// function that returns a promise
var delayed = function(timeout, value) {
    return new Promise(function(resolve) {
        setTimeout(function() { resolve(value); }, timeout);
    });
};

// hash that contains promises (and nested promises)
var tree = {
    a: 1,
    b: delayed(100, {
        b1: delayed(200, 2),
        b2: delayed(300, delayed(50, 3)),
        bNull: delayed(40, null)
    }),
    c: delayed(400, 4),
    d: {
        d1: delayed(500, 'string'),
        d2: delayed(300, { inner: 1 })
    }
};



var fromHash = require('promise-from-hash');

fromHash(tree).then(function(result) {
  /* 
    result will be equal 
    {
        a: 1,
        b: { b1: 2, b2: 3, bNull: null },
        c: 4,
        d: { d1: 'string', d2: { inner: 1} }
    }
  */
});
Resolving all dependencies.. This could take a while as our cache is not yet fully warmed up.