MCPcopy Index your code
hub / github.com/coder/coder / NewCoordination

Method NewCoordination

tailnet/controllers.go:176–209  ·  view source on GitHub ↗

NewCoordination creates a BasicCoordination

(client CoordinatorClient)

Source from the content-addressed store, hash-verified

174
175// NewCoordination creates a BasicCoordination
176func (c *BasicCoordinationController) NewCoordination(client CoordinatorClient) *BasicCoordination {
177 b := &BasicCoordination{
178 logger: c.Logger,
179 errChan: make(chan error, 1),
180 coordinatee: c.Coordinatee,
181 client: client,
182 respLoopDone: make(chan struct{}),
183 sendAcks: c.SendAcks,
184 initiator: c.Initiator,
185 direction: c.Direction,
186 }
187
188 c.Coordinatee.SetNodeCallback(func(node *Node) {
189 pn, err := NodeToProto(node)
190 if err != nil {
191 b.logger.Critical(context.Background(), "failed to convert node", slog.Error(err))
192 b.SendErr(err)
193 return
194 }
195 b.Lock()
196 defer b.Unlock()
197 if b.closed {
198 b.logger.Debug(context.Background(), "ignored node update because coordination is closed")
199 return
200 }
201 err = b.client.Send(&proto.CoordinateRequest{UpdateSelf: &proto.CoordinateRequest_UpdateSelf{Node: pn}})
202 if err != nil {
203 b.SendErr(xerrors.Errorf("write: %w", err))
204 }
205 })
206 go b.respLoop()
207
208 return b
209}
210
211// BasicCoordination handles:
212//

Callers 3

NewMethod · 0.95
NewMethod · 0.80
NewMethod · 0.80

Calls 9

SendErrMethod · 0.95
respLoopMethod · 0.95
NodeToProtoFunction · 0.85
SetNodeCallbackMethod · 0.65
SendMethod · 0.65
ErrorMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected