Skip to content

Instantly share code, notes, and snippets.

@Mostafa-Samir
Created February 22, 2016 18:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mostafa-Samir/7328407167a32a0cf124 to your computer and use it in GitHub Desktop.
Save Mostafa-Samir/7328407167a32a0cf124 to your computer and use it in GitHub Desktop.
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