Index: common/clock/tags.go |
diff --git a/common/clock/tags.go b/common/clock/tags.go |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c19d9db7c29a8a1dc490764cbdba56434b25a9b8 |
--- /dev/null |
+++ b/common/clock/tags.go |
@@ -0,0 +1,30 @@ |
+// 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" |
+) |
+ |
+type clockTagKeyType int |
+ |
+const clockTagKey clockTagKeyType = 0 |
iannucci
2016/02/10 22:30:28
var clockTagKey = &"holds a []string for tagging c
dnj (Google)
2016/02/11 01:26:54
Done.
|
+ |
+// 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 |
+} |