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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « common/clock/systemtimer_test.go ('k') | common/clock/tags_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package clock
6
7 import (
8 "golang.org/x/net/context"
9 )
10
11 var clockTagKey = "clock-tag"
12
13 // Tag returns a derivative Context with the supplied Tag appended to it.
14 //
15 // Tag chains can be used by timers to identify themselves.
16 func Tag(c context.Context, v string) context.Context {
17 return context.WithValue(c, &clockTagKey, append(Tags(c), v))
18 }
19
20 // Tags returns a copy of the set of tags in the current Context.
21 func Tags(c context.Context) []string {
22 if tags, ok := c.Value(&clockTagKey).([]string); ok && len(tags) > 0 {
23 tclone := make([]string, len(tags))
24 copy(tclone, tags)
25 return tclone
26 }
27 return nil
28 }
OLDNEW
« 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