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

Method do

provisionersdk/session.go:342–368  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

340}
341
342func (r *request[R, C]) do() (C, error) {
343 canceledOrComplete := make(chan struct{})
344 result := make(chan C)
345 go func() {
346 c := r.serverFn(r.session, r.req, canceledOrComplete)
347 result <- c
348 }()
349 select {
350 case req := <-r.cancels:
351 close(canceledOrComplete)
352 // wait for server to complete the request, even though we have canceled,
353 // so that we can't start a new request, and so that if the job was close
354 // to completion and the cancel was ignored, we return to complete.
355 c := <-result
356 // verify we got a cancel instead of another request or closed channel --- which is an error!
357 if req.GetCancel() != nil {
358 return c, nil
359 }
360 if req == nil {
361 return c, xerrors.New("got nil while old request still processing")
362 }
363 return c, xerrors.Errorf("got new request %T while old request still processing", req.Type)
364 case c := <-result:
365 close(canceledOrComplete)
366 return c, nil
367 }
368}

Callers 3

handleRequestsMethod · 0.45
handleInitRequestMethod · 0.45
handlePlanRequestMethod · 0.45

Calls 3

GetCancelMethod · 0.80
NewMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected