diff --git a/services/web/public/coffee/ide.coffee b/services/web/public/coffee/ide.coffee index 312d528670..424f71988a 100644 --- a/services/web/public/coffee/ide.coffee +++ b/services/web/public/coffee/ide.coffee @@ -55,7 +55,7 @@ define [ SafariScrollPatcher ) -> - App.controller "IdeController", ($scope, $timeout, ide, localStorage, sixpack, event_tracking, metadata) -> + App.controller "IdeController", ($scope, $timeout, ide, localStorage, sixpack, event_tracking, metadata, $q) -> # Don't freak out if we're already in an apply callback $scope.$originalApply = $scope.$apply $scope.$apply = (fn = () ->) -> @@ -229,17 +229,20 @@ define [ ide.$scope.project.publicAccesLevel = data.newAccessLevel $scope.$digest() - ide.waitFor = (testFunction, callback, timeout, pollInterval=500) -> + ide.waitFor = (testFunction, timeout, pollInterval=500) -> iterationLimit = Math.floor(timeout / pollInterval) iterations = 0 - do tryIteration = () -> - if iterations > iterationLimit - return - iterations += 1 - result = testFunction() - if result? - callback(result) - else - setTimeout(tryIteration, pollInterval) + $q( + (resolve, reject) -> + do tryIteration = () -> + if iterations > iterationLimit + return reject(new Error("waiting too long, #{JSON.stringify({timeout, pollInterval})}")) + iterations += 1 + result = testFunction() + if result? + resolve(result) + else + setTimeout(tryIteration, pollInterval) + ) angular.bootstrap(document.body, ["SharelatexApp"]) diff --git a/services/web/public/coffee/ide/binary-files/controllers/BinaryFileController.coffee b/services/web/public/coffee/ide/binary-files/controllers/BinaryFileController.coffee index ddff96e1d4..ed6fb8ec11 100644 --- a/services/web/public/coffee/ide/binary-files/controllers/BinaryFileController.coffee +++ b/services/web/public/coffee/ide/binary-files/controllers/BinaryFileController.coffee @@ -59,10 +59,12 @@ define [ ide.waitFor( () -> ide.fileTreeManager.findEntityById(new_file_id) - (newFile) -> - ide.binaryFilesManager.openFile(newFile) 5000 ) + .then (newFile) -> + ide.binaryFilesManager.openFile(newFile) + .catch (err) -> + console.warn(err) , 0 ) $scope.refreshError = null diff --git a/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee b/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee index 826d3381f1..5db663cb5e 100644 --- a/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee +++ b/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee @@ -28,10 +28,12 @@ define [ ide.waitFor( () -> ide.fileTreeManager.findEntityById(id) - (entity) -> + 3000 + ) + .then (entity) -> if type == 'doc' ide.editorManager.openDoc(entity) else if type == 'file' ide.binaryFilesManager.openFile(entity) - 3000 - ) + .catch (err) -> + console.warn(err)