Returns true, if state switch succeeds, false if it fails. Returned state is the state before switch. if state switching succeeds, stateFn runs with lock held.
(from, to State, stateFn func())
| 131 | // Returns true, if state switch succeeds, false if it fails. Returned state is the state before switch. |
| 132 | // if state switching succeeds, stateFn runs with lock held. |
| 133 | func (b *BasicService) switchState(from, to State, stateFn func()) (bool, State) { |
| 134 | b.stateMu.Lock() |
| 135 | defer b.stateMu.Unlock() |
| 136 | |
| 137 | if b.state != from { |
| 138 | return false, b.state |
| 139 | } |
| 140 | b.state = to |
| 141 | if stateFn != nil { |
| 142 | stateFn() |
| 143 | } |
| 144 | return true, from |
| 145 | } |
| 146 | |
| 147 | func (b *BasicService) mustSwitchState(from, to State, stateFn func()) { |
| 148 | if ok, _ := b.switchState(from, to, stateFn); !ok { |
no outgoing calls
no test coverage detected