Monday, 13 March 2017

resolve a promise within another promise

In NodeJS, I'm trying to resolve an outside promise when the resolve is within another promise. The outside resolve is called, but the inside one is not.

Why is this? Shouldn't the resolve pass down into the inner promise and resolve up the parent resolve from new Promise(function(resolve...)?

function doIt() {
    return new Promise(function(resolve) {
        resolve('resolve called!'); // This works
        Object.keys(objects).forEach(function(key) {
            return deptSettings(key)
             .then(function(settings) { 
                 ... do stuff
                 if (no more stuff) 
                    resolve('inside resolve called!'); // Not called
            });
        });
    });
}



via Growler

No comments:

Post a Comment