Skip to content

Commit 7ef3b5c

Browse files
committed
self review comments
1 parent 60aae7c commit 7ef3b5c

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

packages/shared/sdk-client/src/datasource/DataSourceStatus.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@ export default interface DataSourceStatus {
2828
* {@link DataSourceStatus.Initializing} or an invalid state such as
2929
* {@link DataSourceState.Interrupted}.
3030
*
31-
* - For {@linkDataSourceState.interrupted}, it is the time that the data source
31+
* - For {@link DataSourceState.interrupted}, it is the time that the data source
3232
* most recently entered an error state, after previously having been
33-
* {@linkDataSourceState.valid}.
33+
* {@link DataSourceState.valid}.
3434
*
35-
* For {@linkDataSourceState.shutdown}, it is the time that the data source
35+
* For {@link DataSourceState.Shutdown}, it is the time that the data source
3636
* encountered an unrecoverable error or that the datasource was explicitly shut down.
37-
*
38-
* For {@linkDataSourceState.networkUnavailable} it is the time that the SDK switched
39-
* the data source off due to network unavailability.
4037
*/
4138
readonly stateSince: number;
4239

packages/shared/sdk-client/src/datasource/DataSourceStatusManager.ts

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ type DataSourceErrorKind = internal.DataSourceErrorKind;
88

99
export type DataSourceStatusCallback = (status: DataSourceStatus) => void;
1010

11+
/**
12+
* Tracks the current data source status and emits updates when the status changes.
13+
*/
1114
export default class DataSourceStatusManager {
1215
private state: DataSourceState;
1316
private stateSinceMillis: number; // UNIX epoch timestamp in milliseconds
@@ -33,6 +36,12 @@ export default class DataSourceStatusManager {
3336
};
3437
}
3538

39+
/**
40+
* Updates the state of the manager.
41+
*
42+
* @param requestedState to track
43+
* @param isError to indicate that the state update is a result of an error occurring.
44+
*/
3645
private updateState(requestedState: DataSourceState, isError = false) {
3746
const newState =
3847
requestedState === DataSourceState.Interrupted && this.state === DataSourceState.Initializing // don't go to interrupted from initializing (recoverable errors when initializing are not noteworthy)
@@ -50,31 +59,51 @@ export default class DataSourceStatusManager {
5059
}
5160
}
5261

53-
off(listener: DataSourceStatusCallback) {
54-
this.emitter.off('dataSourceStatus', listener);
55-
}
56-
62+
/**
63+
* @param listener that will be registered to receive updates
64+
*/
5765
on(listener: DataSourceStatusCallback) {
5866
this.emitter.on('dataSourceStatus', listener);
5967
}
6068

69+
/**
70+
* @param listener that will be unregisted and will no longer receive updates
71+
*/
72+
off(listener: DataSourceStatusCallback) {
73+
this.emitter.off('dataSourceStatus', listener);
74+
}
75+
76+
/**
77+
* Sets the state to {@link DataSourceState.Valid}
78+
*/
6179
setValid() {
6280
this.updateState(DataSourceState.Valid);
6381
}
6482

83+
/**
84+
* Sets the state to {@link DataSourceState.SetOffline}
85+
*/
6586
setOffline() {
6687
this.updateState(DataSourceState.SetOffline);
6788
}
6889

69-
// TODO: SDK-702 - Implement network availability behaviors
70-
// setNetworkUnavailable() {
71-
// this.updateState(DataSourceState.NetworkUnavailable);
72-
// }
73-
90+
/**
91+
* Sets the state to {@link DataSourceState.Shutdown}
92+
*/
7493
setShutdown() {
7594
this.updateState(DataSourceState.Shutdown);
7695
}
7796

97+
/**
98+
* Reports a datasource error to this manager. Since the {@link DataSourceStatus} includes error
99+
* information, it is possible that that a {@link DataSourceStatus} update is emitted with
100+
* the same {@link DataSourceState}.
101+
*
102+
* @param kind of the error
103+
* @param message for the error
104+
* @param statusCode of the error if there was one
105+
* @param recoverable to indicate that the error is anticipated to be recoverable
106+
*/
78107
setError(
79108
kind: DataSourceErrorKind,
80109
message: string,
@@ -90,4 +119,9 @@ export default class DataSourceStatusManager {
90119
this.errorInfo = errorInfo;
91120
this.updateState(recoverable ? DataSourceState.Interrupted : DataSourceState.Shutdown, true);
92121
}
122+
123+
// TODO: SDK-702 - Implement network availability behaviors
124+
// setNetworkUnavailable() {
125+
// this.updateState(DataSourceState.NetworkUnavailable);
126+
// }
93127
}

0 commit comments

Comments
 (0)