mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 21:31:36 +02:00
Use a promise (with Angular's $q) in waitFor
This commit is contained in:
@@ -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"])
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user