* Transition the transaction in the state machine * @param nextState - The new state to transition to
(nextState: TxnState)
| 147 | * @param nextState - The new state to transition to |
| 148 | */ |
| 149 | transition(nextState: TxnState): void { |
| 150 | const nextStates = stateMachine[this.state]; |
| 151 | if (nextStates && nextStates.includes(nextState)) { |
| 152 | this.state = nextState; |
| 153 | if ( |
| 154 | this.state === TxnState.NO_TRANSACTION || |
| 155 | this.state === TxnState.STARTING_TRANSACTION || |
| 156 | this.state === TxnState.TRANSACTION_ABORTED |
| 157 | ) { |
| 158 | this.unpinServer(); |
| 159 | } |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | throw new MongoRuntimeError( |
| 164 | `Attempted illegal state transition from [${this.state}] to [${nextState}]` |
| 165 | ); |
| 166 | } |
| 167 | |
| 168 | pinServer(server: Server): void { |
| 169 | if (this.isActive) { |
no test coverage detected