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

Unified Diff: common/clock/external.go

Issue 1679023005: Add Context cancellation to clock. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Actually upload the patch. 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
« no previous file with comments | « common/clock/clockcontext_test.go ('k') | common/clock/external_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/clock/external.go
diff --git a/common/clock/external.go b/common/clock/external.go
index acca11b0cdc651295b391da3426ffb8c35655e66..026365e9136636b454386388e6bf82556dd8a402 100644
--- a/common/clock/external.go
+++ b/common/clock/external.go
@@ -10,18 +10,15 @@ import (
"golang.org/x/net/context"
)
-// Context key for clock.
-type clockKeyType int
-
// Unique value for clock key.
-var clockKey clockKeyType
+var clockKey = "clock.Clock"
// Factory is a generator function that produces a Clock instnace.
type Factory func(context.Context) Clock
// SetFactory creates a new Context using the supplied Clock factory.
func SetFactory(ctx context.Context, f Factory) context.Context {
- return context.WithValue(ctx, clockKey, f)
+ return context.WithValue(ctx, &clockKey, f)
}
// Set creates a new Context using the supplied Clock.
@@ -32,7 +29,7 @@ func Set(ctx context.Context, c Clock) context.Context {
// Get returns the Clock set in the supplied Context, defaulting to
// SystemClock() if none is set.
func Get(ctx context.Context) (clock Clock) {
- if v := ctx.Value(clockKey); v != nil {
+ if v := ctx.Value(&clockKey); v != nil {
if f, ok := v.(Factory); ok {
clock = f(ctx)
}
@@ -50,16 +47,16 @@ func Now(ctx context.Context) time.Time {
// Sleep calls Clock.Sleep on the Clock instance stored in the supplied Context.
func Sleep(ctx context.Context, d time.Duration) {
- Get(ctx).Sleep(d)
+ Get(ctx).Sleep(ctx, d)
}
// NewTimer calls Clock.NewTimer on the Clock instance stored in the supplied
// Context.
func NewTimer(ctx context.Context) Timer {
- return Get(ctx).NewTimer()
+ return Get(ctx).NewTimer(ctx)
}
// After calls Clock.After on the Clock instance stored in the supplied Context.
-func After(ctx context.Context, d time.Duration) <-chan time.Time {
- return Get(ctx).After(d)
+func After(ctx context.Context, d time.Duration) <-chan TimerResult {
+ return Get(ctx).After(ctx, d)
}
« no previous file with comments | « common/clock/clockcontext_test.go ('k') | common/clock/external_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698