Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 type clockTagKeyType int | |
| 12 | |
| 13 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.
| |
| 14 | |
| 15 // Tag returns a derivative Context with the supplied Tag appended to it. | |
| 16 // | |
| 17 // Tag chains can be used by timers to identify themselves. | |
| 18 func Tag(c context.Context, v string) context.Context { | |
| 19 return context.WithValue(c, clockTagKey, append(Tags(c), v)) | |
| 20 } | |
| 21 | |
| 22 // Tags returns a copy of the set of tags in the current Context. | |
| 23 func Tags(c context.Context) []string { | |
| 24 if tags, ok := c.Value(clockTagKey).([]string); ok && len(tags) > 0 { | |
| 25 tclone := make([]string, len(tags)) | |
| 26 copy(tclone, tags) | |
| 27 return tclone | |
| 28 } | |
| 29 return nil | |
| 30 } | |
| OLD | NEW |