Skip to content

Commit fb2a1f9

Browse files
committed
doc(LayerUpdateState): update and refine documentation
1 parent 7f6b21a commit fb2a1f9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

packages/Main/src/Layer/LayerUpdateState.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,19 @@ class LayerUpdateState {
4242
};
4343
}
4444

45+
/**
46+
* Checks if the update has finished successfully.
47+
*/
4548
hasFinished() {
4649
return UPDATE_STATE.FINISHED == this.state;
4750
}
4851

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+
*/
4958
canTryUpdate(timestamp = Date.now()) {
5059
switch (this.state) {
5160
case UPDATE_STATE.IDLE: {
@@ -64,6 +73,9 @@ class LayerUpdateState {
6473
}
6574
}
6675

76+
/**
77+
* Gives the number of seconds to wait before the next retry attempt.
78+
*/
6779
secondsUntilNextTry() {
6880
if (this.state !== UPDATE_STATE.ERROR) {
6981
return 0;
@@ -74,19 +86,36 @@ class LayerUpdateState {
7486
return PAUSE_BETWEEN_ERRORS[idx];
7587
}
7688

89+
/**
90+
* Marks the beginning of a new update attempt.
91+
*/
7792
newTry() {
7893
this.state = UPDATE_STATE.PENDING;
7994
}
8095

96+
/**
97+
* Marks the update as successful. It resets the error tracking.
98+
*/
8199
success() {
82100
this.lastErrorTimestamp = 0;
83101
this.state = UPDATE_STATE.IDLE;
84102
}
85103

104+
/**
105+
* Marks the update as permanently finished, preventing further update
106+
* attempts.
107+
*/
86108
noMoreUpdatePossible() {
87109
this.state = UPDATE_STATE.FINISHED;
88110
}
89111

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+
*/
90119
noData(failureParams: { targetLevel: number }) {
91120
this.state = UPDATE_STATE.IDLE;
92121
this.failureParams.lowestLevelError = Math.min(
@@ -95,6 +124,15 @@ class LayerUpdateState {
95124
);
96125
}
97126

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+
*/
98136
failure(timestamp: number, definitive: boolean, failureParams: { targetLevel: number }) {
99137
if (failureParams && failureParams.targetLevel != undefined) {
100138
this.failureParams.lowestLevelError = Math.min(
@@ -107,6 +145,9 @@ class LayerUpdateState {
107145
this.errorCount++;
108146
}
109147

148+
/**
149+
* Checks if the layer is currently in an error state.
150+
*/
110151
inError() {
111152
return this.state == UPDATE_STATE.DEFINITIVE_ERROR || this.state == UPDATE_STATE.ERROR;
112153
}

0 commit comments

Comments
 (0)