Skip to content

Commit a88a52d

Browse files
committed
Adds numRetries parameter to uiGmapIsReady.promise()
1 parent f76a6b9 commit a88a52d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/coffee/directives/api/utils/is-ready.coffee

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@ angular.module('uiGmapgoogle-maps.directives.api.utils')
22
.service 'uiGmapIsReady', ['$q', '$timeout', ($q, $timeout) ->
33
_ctr = 0
44
_proms = []
5-
_currentCheckNum = 1
6-
_maxCtrChecks = 50 #consider making this a angular const so it can be overriden by users
75

86
_promises = ->
97
$q.all _proms
108

119

12-
_checkIfReady = (deferred, expectedInstances) ->
10+
_checkIfReady = (deferred, expectedInstances, retriesLeft) ->
1311
$timeout ->
14-
if _currentCheckNum >= _maxCtrChecks
12+
if retriesLeft <= 0
1513
deferred.reject('Your maps are not found we have checked the maximum amount of times. :)')
16-
_currentCheckNum += 1
1714
if _ctr != expectedInstances
18-
_checkIfReady(deferred, expectedInstances)
15+
_checkIfReady(deferred, expectedInstances, retriesLeft-1)
1916
else
2017
deferred.resolve(_promises())
2118
, 100
@@ -33,9 +30,9 @@ angular.module('uiGmapgoogle-maps.directives.api.utils')
3330
instances: ->
3431
_ctr
3532

36-
promise: (expectedInstances = 1) ->
33+
promise: (expectedInstances = 1, numRetries = 50) ->
3734
d = $q.defer()
38-
_checkIfReady(d, expectedInstances)
35+
_checkIfReady(d, expectedInstances, numRetries)
3936
d.promise
4037

4138
reset: ->

0 commit comments

Comments
 (0)