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

Method StopAsync

services/basic_service.go:231–250  ·  view source on GitHub ↗

StopAsync is part of Service interface.

()

Source from the content-addressed store, hash-verified

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