Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: common/clock/clockcontext.go

Issue 1679023005: Add Context cancellation to clock. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Updated from comments, conformant to time interface. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: common/clock/clockcontext.go
diff --git a/common/clock/clockcontext.go b/common/clock/clockcontext.go
index 979f2fc0588d02a29fc808553ff43742c9dbb640..1b9df12e35e83e0a6be23c9ece273f3e7f04fafd 100644
--- a/common/clock/clockcontext.go
+++ b/common/clock/clockcontext.go
@@ -71,11 +71,8 @@ func WithDeadline(parent context.Context, deadline time.Time) (context.Context,
// Invoke our cancelFunc after the specified time.
go func() {
- select {
- case <-c.Done():
- break
-
- case <-After(c, d):
+ if ar := <-After(c, d); ar.Err == nil {
+ // Timer expired naturally.
c.setError(context.DeadlineExceeded)
cancelFunc()
}

Powered by Google App Engine
This is Rietveld 408576698