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

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: 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/tags.go
diff --git a/common/clock/tags.go b/common/clock/tags.go
new file mode 100644
index 0000000000000000000000000000000000000000..31bfa60bf206339e6ab3f0fbc2119bb25ea162ff
--- /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 = &[]string{"clock-tag"}
iannucci 2016/02/11 02:24:04 so I think this is what I was thinking of: https:
dnj (Google) 2016/02/11 17:22:37 OK, done.
iannucci 2016/02/12 03:35:35 OH REALLY!?
+
+// 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
+}

Powered by Google App Engine
This is Rietveld 408576698