deadline.go 323 B

123456789101112
  1. package contextx
  2. import (
  3. "context"
  4. "time"
  5. )
  6. // ShrinkDeadline returns a new Context with proper deadline base on the given ctx and timeout.
  7. // And returns a cancel function as well.
  8. func ShrinkDeadline(ctx context.Context, timeout time.Duration) (context.Context, func()) {
  9. return context.WithTimeout(ctx, timeout)
  10. }