MCPcopy Create free account
hub / github.com/cortexproject/cortex / switchState

Method switchState

pkg/util/services/basic_service.go:130–142  ·  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

128// Returns true, if state switch succeeds, false if it fails. Returned state is the state before switch.
129// if state switching succeeds, stateFn runs with lock held.
130func (b *BasicService) switchState(from, to State, stateFn func()) (bool, State) {
131 b.stateMu.Lock()
132 defer b.stateMu.Unlock()
133
134 if b.state != from {
135 return false, b.state
136 }
137 b.state = to
138 if stateFn != nil {
139 stateFn()
140 }
141 return true, from
142}
143
144func (b *BasicService) mustSwitchState(from, to State, stateFn func()) {
145 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