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

Unified Diff: common/clock/tags.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/systemtimer_test.go ('k') | common/clock/tags_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/clock/tags.go
diff --git a/common/clock/tags.go b/common/clock/tags.go
new file mode 100644
index 0000000000000000000000000000000000000000..8f15aeb954b9645948eeaf2cb6fb70a37c279293
--- /dev/null
+++ b/common/clock/tags.go
@@ -0,0 +1,28 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package clock
+
+import (
+ "golang.org/x/net/context"
+)
+
+var clockTagKey = "clock-tag"
+
+// Tag returns a derivative Context with the supplied Tag appended to it.
+//
+// Tag chains can be used by timers to identify themselves.
+func Tag(c context.Context, v string) context.Context {
+ return context.WithValue(c, &clockTagKey, append(Tags(c), v))
+}
+
+// Tags returns a copy of the set of tags in the current Context.
+func Tags(c context.Context) []string {
+ if tags, ok := c.Value(&clockTagKey).([]string); ok && len(tags) > 0 {
+ tclone := make([]string, len(tags))
+ copy(tclone, tags)
+ return tclone
+ }
+ return nil
+}
« no previous file with comments | « common/clock/systemtimer_test.go ('k') | common/clock/tags_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698