mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Use a promise (with Angular's $q
) in waitFor
This commit is contained in:
parent
8be4279165
commit
cfc17d56e8
3 changed files with 23 additions and 16 deletions
|
@ -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
|
||||
$q(
|
||||
(resolve, reject) ->
|
||||
do tryIteration = () ->
|
||||
if iterations > iterationLimit
|
||||
return
|
||||
return reject(new Error("waiting too long, #{JSON.stringify({timeout, pollInterval})}"))
|
||||
iterations += 1
|
||||
result = testFunction()
|
||||
if result?
|
||||
callback(result)
|
||||
resolve(result)
|
||||
else
|
||||
setTimeout(tryIteration, pollInterval)
|
||||
)
|
||||
|
||||
angular.bootstrap(document.body, ["SharelatexApp"])
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue