()
| 209 | |
| 210 | // This function is not guaranteed to save state before returning |
| 211 | async saveState(): Promise<void> { |
| 212 | switch (this.meta) { |
| 213 | case StateManagerImplState.INITIAL: |
| 214 | // Make sure not to overwrite data before it is loaded |
| 215 | this.logWarn('StateManager.saveState was called before StateManager.loadState(). Possible data race! Loading data instead.'); |
| 216 | return this.loadState(); |
| 217 | case StateManagerImplState.LOADING: |
| 218 | // Need to wait for active read operation to end |
| 219 | this.logWarn('StateManager.saveState was called before StateManager.loadState() resolved. Possible data race! Loading data instead.'); |
| 220 | return this.barrier!.entry(); |
| 221 | case StateManagerImplState.READY: { |
| 222 | this.meta = StateManagerImplState.SAVING; |
| 223 | const entry = this.barrier!.entry(); |
| 224 | this.saveStateInternal(); |
| 225 | return entry; |
| 226 | } |
| 227 | case StateManagerImplState.SAVING: |
| 228 | // Another save is in progress |
| 229 | this.meta = StateManagerImplState.SAVING_OVERRIDE; |
| 230 | return this.barrier!.entry(); |
| 231 | case StateManagerImplState.SAVING_OVERRIDE: |
| 232 | return this.barrier!.entry(); |
| 233 | case StateManagerImplState.ONCHANGE_RACE: |
| 234 | this.logWarn('StateManager.saveState was called during active read/write operation. Possible data race! Loading data instead.'); |
| 235 | return this.barrier!.entry(); |
| 236 | case StateManagerImplState.RECOVERY: |
| 237 | this.logWarn('StateManager.saveState was called during active read operation. Possible data race! Waiting for data load instead.'); |
| 238 | return this.barrier!.entry(); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | private loadStateInternal() { |
| 243 | this.storage.get(this.localStorageKey, (data: any) => { |
nothing calls this directly
no test coverage detected