Created
August 31, 2016 14:50
-
-
Save umdstu/b51c2bdf2a889e9b7024772884c674af to your computer and use it in GitHub Desktop.
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
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); | |
}); | |
} |
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 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