@@ -42,10 +42,19 @@ class LayerUpdateState {
42
42
} ;
43
43
}
44
44
45
+ /**
46
+ * Checks if the update has finished successfully.
47
+ */
45
48
hasFinished ( ) {
46
49
return UPDATE_STATE . FINISHED == this . state ;
47
50
}
48
51
52
+ /**
53
+ * Checks if an update can be attempted based on the current update state.
54
+ *
55
+ * @param timestamp - Current timestamp in milliseconds (defaults to
56
+ * Date.now()).
57
+ */
49
58
canTryUpdate ( timestamp = Date . now ( ) ) {
50
59
switch ( this . state ) {
51
60
case UPDATE_STATE . IDLE : {
@@ -64,6 +73,9 @@ class LayerUpdateState {
64
73
}
65
74
}
66
75
76
+ /**
77
+ * Gives the number of seconds to wait before the next retry attempt.
78
+ */
67
79
secondsUntilNextTry ( ) {
68
80
if ( this . state !== UPDATE_STATE . ERROR ) {
69
81
return 0 ;
@@ -74,19 +86,36 @@ class LayerUpdateState {
74
86
return PAUSE_BETWEEN_ERRORS [ idx ] ;
75
87
}
76
88
89
+ /**
90
+ * Marks the beginning of a new update attempt.
91
+ */
77
92
newTry ( ) {
78
93
this . state = UPDATE_STATE . PENDING ;
79
94
}
80
95
96
+ /**
97
+ * Marks the update as successful. It resets the error tracking.
98
+ */
81
99
success ( ) {
82
100
this . lastErrorTimestamp = 0 ;
83
101
this . state = UPDATE_STATE . IDLE ;
84
102
}
85
103
104
+ /**
105
+ * Marks the update as permanently finished, preventing further update
106
+ * attempts.
107
+ */
86
108
noMoreUpdatePossible ( ) {
87
109
this . state = UPDATE_STATE . FINISHED ;
88
110
}
89
111
112
+ /**
113
+ * Handles the case where no data is available for the requested level.
114
+ * Updates the lowest level error tracking for future retry attempts.
115
+ *
116
+ * @param failureParams - The current context of the failure (this includes
117
+ * the current updated level).
118
+ */
90
119
noData ( failureParams : { targetLevel : number } ) {
91
120
this . state = UPDATE_STATE . IDLE ;
92
121
this . failureParams . lowestLevelError = Math . min (
@@ -95,6 +124,15 @@ class LayerUpdateState {
95
124
) ;
96
125
}
97
126
127
+ /**
128
+ * Handles update failures. An error is either definitive or retryable (up
129
+ * to four attempts).
130
+ *
131
+ * @param timestamp - The timestamp when the failure occurred.
132
+ * @param definitive - Whether this error stops the update process.
133
+ * @param failureParams - The current context of the failure (this includes
134
+ * the current updated level).
135
+ */
98
136
failure ( timestamp : number , definitive : boolean , failureParams : { targetLevel : number } ) {
99
137
if ( failureParams && failureParams . targetLevel != undefined ) {
100
138
this . failureParams . lowestLevelError = Math . min (
@@ -107,6 +145,9 @@ class LayerUpdateState {
107
145
this . errorCount ++ ;
108
146
}
109
147
148
+ /**
149
+ * Checks if the layer is currently in an error state.
150
+ */
110
151
inError ( ) {
111
152
return this . state == UPDATE_STATE . DEFINITIVE_ERROR || this . state == UPDATE_STATE . ERROR ;
112
153
}
0 commit comments