如何将其重构为 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
}, ...