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)
| 353 | // the returned context is canceled. The context values will only be used from |
| 354 | // the first context. |
| 355 | func mergeContexts(base, other context.Context) context.Context { |
| 356 | ctx, cancel := context.WithCancel(base) |
| 357 | go func() { |
| 358 | defer cancel() |
| 359 | select { |
| 360 | case <-base.Done(): |
| 361 | case <-other.Done(): |
| 362 | } |
| 363 | }() |
| 364 | return ctx |
| 365 | } |