これを Promise/A パターンにリファクタリングして、タイマーをなくし、送り返された Promise だけを処理するにはどうすればよいですか?
$scope.manageAccess = function () {
queuedRepository.queuedItems().then(function (queuedItems) {
if (queuedItems.length === 0) {
var path = globalLocation.pathname(),
hash = globalLocation.hashNoBang();
globalLocation.url(app.vroot() + "SharedSubmission/" + $scope.data.submissionVersion.id + "?path=" + path + "&hash=" + hash);
} else {
console.log("Pending items in the queue... Retrying in 500ms.");
setTimeout(function () {
$scope.manageAccess();
}, 500);
}
});
};
キューに入れられたリポジトリ
return {
queuedItems: function() {
return persistentCache.list('qr'); // Return Promise
}, ...