()
| 179 | } |
| 180 | |
| 181 | private saveStateInternal() { |
| 182 | this.storage.set({[this.localStorageKey]: this.collectState()}, () => { |
| 183 | switch (this.meta) { |
| 184 | case StateManagerImplState.INITIAL: |
| 185 | // fallthrough |
| 186 | case StateManagerImplState.LOADING: |
| 187 | // fallthrough |
| 188 | case StateManagerImplState.READY: |
| 189 | // fallthrough |
| 190 | case StateManagerImplState.RECOVERY: |
| 191 | this.logWarn('Unexpected state. Possible data race!'); |
| 192 | this.meta = StateManagerImplState.ONCHANGE_RACE; |
| 193 | this.loadStateInternal(); |
| 194 | return; |
| 195 | case StateManagerImplState.SAVING: |
| 196 | this.meta = StateManagerImplState.READY; |
| 197 | this.releaseBarrier(); |
| 198 | return; |
| 199 | case StateManagerImplState.SAVING_OVERRIDE: |
| 200 | this.meta = StateManagerImplState.SAVING; |
| 201 | this.saveStateInternal(); |
| 202 | return; |
| 203 | case StateManagerImplState.ONCHANGE_RACE: |
| 204 | this.meta = StateManagerImplState.RECOVERY; |
| 205 | this.loadStateInternal(); |
| 206 | } |
| 207 | }); |
| 208 | } |
| 209 | |
| 210 | // This function is not guaranteed to save state before returning |
| 211 | async saveState(): Promise<void> { |
no test coverage detected