Skip to content

mikach/promise-from-hash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Promise.all for hash Build Status

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} }
    }
  */
});

About

Promise.all for hash

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published