Add a waitFor helper to the ide object

This commit is contained in:
Shane Kilkelly 2018-05-25 10:36:20 +01:00
parent 0cb5beb689
commit 3849bcfb40

View file

@ -229,4 +229,18 @@ define [
ide.$scope.project.publicAccesLevel = data.newAccessLevel
$scope.$digest()
ide.waitFor = (fn, callback, timeout) ->
sleepTime = 500
iterationLimit = Math.floor(timeout / sleepTime)
iterations = 0
do tryIteration = () ->
if iterations > iterationLimit
return
iterations += 1
result = fn()
if result?
callback(result)
else
setTimeout(tryIteration, sleepTime)
angular.bootstrap(document.body, ["SharelatexApp"])