Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
Use Until instead of Sub in WithDeadline
Browse files Browse the repository at this point in the history
  • Loading branch information
morigs committed Nov 12, 2021
1 parent 6754fcb commit 3e4357c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion context.go
Expand Up @@ -18,7 +18,7 @@ func (m *Mock) WithDeadline(parent context.Context, deadline time.Time) (context
}
ctx := &timerCtx{clock: m, parent: parent, deadline: deadline, done: make(chan struct{})}
propagateCancel(parent, ctx)
dur := deadline.Sub(m.Now())
dur := m.Until(deadline)
if dur <= 0 {
ctx.cancel(context.DeadlineExceeded) // deadline has already passed
return ctx, func() { ctx.cancel(context.Canceled) }
Expand Down

0 comments on commit 3e4357c

Please sign in to comment.