RequestSafeStateChange safely requests a state change from a different goroutine
(nextState State)
| 170 | |
| 171 | // RequestSafeStateChange safely requests a state change from a different goroutine |
| 172 | func (ts *ThreadState) RequestSafeStateChange(nextState State) bool { |
| 173 | ts.mu.Lock() |
| 174 | switch ts.currentState { |
| 175 | // disallow state changes if shutting down or done |
| 176 | case ShuttingDown, Done, Reserved: |
| 177 | ts.mu.Unlock() |
| 178 | |
| 179 | return false |
| 180 | // ready and inactive are safe states to transition from |
| 181 | case Ready, Inactive: |
| 182 | ts.currentState = nextState |
| 183 | ts.notifySubscribers(nextState) |
| 184 | ts.mu.Unlock() |
| 185 | |
| 186 | return true |
| 187 | } |
| 188 | ts.mu.Unlock() |
| 189 | |
| 190 | // wait for the state to change to a safe state |
| 191 | ts.WaitFor(Ready, Inactive, ShuttingDown) |
| 192 | |
| 193 | return ts.RequestSafeStateChange(nextState) |
| 194 | } |
| 195 | |
| 196 | // MarkAsWaiting hints that the thread reached a stable state and is waiting for requests or shutdown |
| 197 | func (ts *ThreadState) MarkAsWaiting(isWaiting bool) { |
no test coverage detected