You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
321 B
18 lines
321 B
5 years ago
|
package redis
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func shrinkDeadline(ctx context.Context, timeout time.Duration) time.Time {
|
||
|
var timeoutTime = time.Now().Add(timeout)
|
||
|
if ctx == nil {
|
||
|
return timeoutTime
|
||
|
}
|
||
|
if deadline, ok := ctx.Deadline(); ok && timeoutTime.After(deadline) {
|
||
|
return deadline
|
||
|
}
|
||
|
return timeoutTime
|
||
|
}
|