Skip to content

Instantly share code, notes, and snippets.

@umdstu
Created August 31, 2016 14:50
Show Gist options
  • Save umdstu/b51c2bdf2a889e9b7024772884c674af to your computer and use it in GitHub Desktop.
Save umdstu/b51c2bdf2a889e9b7024772884c674af to your computer and use it in GitHub Desktop.
var service = {};
service.findAll = function(scope) {
service.define()
.then(function(resp) {
return promiseWhile(function() { return scope.finished}, service.nextPage.bind(service, scope));
})
.finally(function(resp) {
callback(scope);
});
}
function promiseWhile(condition, action) {
var resolver = $q.defer();
var loop = function() {
if (condition()) return resolver.resolve();
return $q.when(action()).then(function(r) {
return $timeout(loop, 2000);
}).catch(resolver.reject);
}
$timeout(loop, 2000);
return resolver.promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment