Files
go-zero/core/contextx/deadline.go

13 lines
323 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package contextx
import (
"context"
"time"
)
// ShrinkDeadline returns a new Context with proper deadline base on the given ctx and timeout.
// And returns a cancel function as well.
2020-07-26 17:09:05 +08:00
func ShrinkDeadline(ctx context.Context, timeout time.Duration) (context.Context, func()) {
return context.WithTimeout(ctx, timeout)
2020-07-26 17:09:05 +08:00
}