Created
February 22, 2016 18:05
-
-
Save Mostafa-Samir/7328407167a32a0cf124 to your computer and use it in GitHub Desktop.
A solution to multiple dependencies problem : http://mostafa-samir.github.io/async-recursive-patterns-pt2/#comment-2522702892
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadMeatOf(name, list) { | |
var deferred = Promise.defer(); | |
http.get('http://localhost:8080/meta/' + name, function(response) { | |
var responseBody = ""; // will hold the response body as it comes | |
// join the data chuncks as they come | |
response.on('data', function(chunck) { responseBody += chunck }); | |
response.on('end', function() { | |
var jsonResponse = JSON.parse(responseBody); | |
list.push(name); | |
// iterate asynchronously over the dependencies | |
// you can use WaterfallOver if you want to handle the dependencies in order | |
IterateOver(jsonResponse.dependencies, function(dep, report) { | |
loadMetaOf(dep, list) | |
.then(function() { | |
report(); | |
}); | |
}, function() { | |
deferred.resolve(); | |
}); | |
}); | |
}); | |
return deferred.promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment