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

Method StopAsync

pkg/util/services/basic_service.go:228–247  ·  view source on GitHub ↗

StopAsync is part of Service interface.

()

Source from the content-addressed store, hash-verified

226
227// StopAsync is part of Service interface.
228func (b *BasicService) StopAsync() {
229 if s := b.State(); s == Stopping || s == Terminated || s == Failed {
230 // no need to do anything
231 return
232 }
233
234 terminated, _ := b.switchState(New, Terminated, func() {
235 // Service wasn't started yet, and it won't be now.
236 // Notify waiters and listeners.
237 close(b.runningWaitersCh)
238 close(b.terminatedWaitersCh)
239 b.notifyListeners(func(l Listener) { l.Terminated(New) }, true)
240 })
241
242 if !terminated {
243 // Service is Starting or Running. Just cancel the context (it must exist,
244 // as it is created when switching from New to Starting state)
245 b.serviceCancel()
246 }
247}
248
249// ServiceContext returns context that this service uses internally for controlling its lifecycle. It is the same context that
250// is passed to Starting and Running functions, and is based on context passed to the service via StartAsync.

Callers

nothing calls this directly

Calls 4

StateMethod · 0.95
switchStateMethod · 0.95
notifyListenersMethod · 0.95
TerminatedMethod · 0.65

Tested by

no test coverage detected