From 425430f67c926b065862ad901fbf524f7e8ec3e3 Mon Sep 17 00:00:00 2001 From: Oraoto <24709398+oraoto@users.noreply.github.com> Date: Sat, 3 Apr 2021 21:25:32 +0800 Subject: [PATCH] Simplify contextx.ShrinkDeadline (#596) --- core/contextx/deadline.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/core/contextx/deadline.go b/core/contextx/deadline.go index a97388bb..0a3c3fae 100644 --- a/core/contextx/deadline.go +++ b/core/contextx/deadline.go @@ -8,12 +8,5 @@ import ( // 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()) { - if deadline, ok := ctx.Deadline(); ok { - leftTime := time.Until(deadline) - if leftTime < timeout { - timeout = leftTime - } - } - - return context.WithDeadline(ctx, time.Now().Add(timeout)) + return context.WithTimeout(ctx, timeout) }