mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
13 lines
323 B
Go
13 lines
323 B
Go
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.
|
|
func ShrinkDeadline(ctx context.Context, timeout time.Duration) (context.Context, func()) {
|
|
return context.WithTimeout(ctx, timeout)
|
|
}
|