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 |
+} |