()
| 340 | } |
| 341 | |
| 342 | func (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 | } |
no test coverage detected