MCPcopy
hub / github.com/grafana/dskit / switchState

Method switchState

services/basic_service.go:133–145  ·  view source on GitHub ↗

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())

Source from the content-addressed store, hash-verified

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.
133func (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
147func (b *BasicService) mustSwitchState(from, to State, stateFn func()) {
148 if ok, _ := b.switchState(from, to, stateFn); !ok {

Callers 3

StartAsyncMethod · 0.95
mustSwitchStateMethod · 0.95
StopAsyncMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected