mergeContexts merges two contexts together, so that if either is canceled the returned context is canceled. The context values will only be used from the first context.
(base, other context.Context)
| 428 | // the returned context is canceled. The context values will only be used from |
| 429 | // the first context. |
| 430 | func mergeContexts(base, other context.Context) context.Context { |
| 431 | ctx, cancel := context.WithCancel(base) |
| 432 | go func() { |
| 433 | defer cancel() |
| 434 | select { |
| 435 | case <-base.Done(): |
| 436 | case <-other.Done(): |
| 437 | } |
| 438 | }() |
| 439 | return ctx |
| 440 | } |