context.go 776 B

123456789101112131415161718192021222324
  1. package puddle
  2. import (
  3. "context"
  4. "time"
  5. )
  6. // valueCancelCtx combines two contexts into one. One context is used for values and the other is used for cancellation.
  7. type valueCancelCtx struct {
  8. valueCtx context.Context
  9. cancelCtx context.Context
  10. }
  11. func (ctx *valueCancelCtx) Deadline() (time.Time, bool) { return ctx.cancelCtx.Deadline() }
  12. func (ctx *valueCancelCtx) Done() <-chan struct{} { return ctx.cancelCtx.Done() }
  13. func (ctx *valueCancelCtx) Err() error { return ctx.cancelCtx.Err() }
  14. func (ctx *valueCancelCtx) Value(key any) any { return ctx.valueCtx.Value(key) }
  15. func newValueCancelCtx(valueCtx, cancelContext context.Context) context.Context {
  16. return &valueCancelCtx{
  17. valueCtx: valueCtx,
  18. cancelCtx: cancelContext,
  19. }
  20. }