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

Function NewManager

services/manager.go:56–81  ·  view source on GitHub ↗

NewManager creates new service manager. It needs at least one service, and all services must be in New state.

(services ...Service)

Source from the content-addressed store, hash-verified

54
55// NewManager creates new service manager. It needs at least one service, and all services must be in New state.
56func NewManager(services ...Service) (*Manager, error) {
57 if len(services) == 0 {
58 return nil, errors.New("no services")
59 }
60
61 m := &Manager{
62 services: services,
63 byState: map[State][]Service{},
64 healthyCh: make(chan struct{}),
65 stoppedCh: make(chan struct{}),
66 }
67
68 for _, s := range services {
69 st := s.State()
70 if st != New {
71 return nil, fmt.Errorf("unexpected service state: %v", st)
72 }
73
74 m.byState[st] = append(m.byState[st], s)
75 }
76
77 for _, s := range services {
78 s.AddListener(newManagerServiceListener(m, s))
79 }
80 return m, nil
81}
82
83// StartAsync initiates service startup on all the services being managed.
84// It is only valid to call this method if all of the services are New.

Calls 4

ErrorfMethod · 0.80
StateMethod · 0.65
AddListenerMethod · 0.65