Skip to content

Instantly share code, notes, and snippets.

@danielsotopino
Created December 15, 2017 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielsotopino/20cb062d0a59ee583ffcb24e2bdbed5d to your computer and use it in GitHub Desktop.
Save danielsotopino/20cb062d0a59ee583ffcb24e2bdbed5d to your computer and use it in GitHub Desktop.
Synchronous recursive promises
$scope.recurse = function(promises, promisesLength, results) {
if (promisesLength === 1) {
return promises[0].then(function(data){
results.push(data);
return results;
});
}
return promises[promisesLength-1].then(function(data) {
results.push(data);
return $scope.recurse(promises, promisesLength - 1, results);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment