github.com/andoma-go/puddle/v2@v2.2.1/context.go (about)

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