OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Package memlock allows multiple appengine handlers to coordinate best-effort | 5 // Package memlock allows multiple appengine handlers to coordinate best-effort |
6 // mutual execution via memcache. "best-effort" here means "best-effort"... | 6 // mutual execution via memcache. "best-effort" here means "best-effort"... |
7 // memcache is not reliable. However, colliding on memcache is a lot cheaper | 7 // memcache is not reliable. However, colliding on memcache is a lot cheaper |
8 // than, for example, colliding with datastore transactions. | 8 // than, for example, colliding with datastore transactions. |
9 package memlock | 9 package memlock |
10 | 10 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 testStopCB, _ := ctx.Value(testStopCBKey).(func()) | 145 testStopCB, _ := ctx.Value(testStopCBKey).(func()) |
146 | 146 |
147 // This goroutine checks to see if we still posess the lock, and refresh es it | 147 // This goroutine checks to see if we still posess the lock, and refresh es it |
148 // if we do. | 148 // if we do. |
149 go func() { | 149 go func() { |
150 defer func() { | 150 defer func() { |
151 cancelFunc() | 151 cancelFunc() |
152 close(finished) | 152 close(finished) |
153 }() | 153 }() |
154 | 154 |
155 checkLoop: | |
156 for { | 155 for { |
157 » » » select { | 156 » » » if (<-clock.After(subCtx, delay)).Err != nil { |
dnj (Google)
2016/02/10 03:40:08
Nice, eh?
| |
158 » » » case <-subCtx.Done(): | 157 » » » » break |
159 » » » » break checkLoop | |
160 » » » case <-clock.Get(ctx).After(delay): | |
161 } | 158 } |
162 if !checkAnd(refresh) { | 159 if !checkAnd(refresh) { |
163 log.Warningf("lost lock: %s", err) | 160 log.Warningf("lost lock: %s", err) |
164 return | 161 return |
165 } | 162 } |
166 } | 163 } |
167 | 164 |
168 if testStopCB != nil { | 165 if testStopCB != nil { |
169 testStopCB() | 166 testStopCB() |
170 } | 167 } |
171 checkAnd(release) | 168 checkAnd(release) |
172 }() | 169 }() |
173 | 170 |
174 return f(subCtx) | 171 return f(subCtx) |
175 } | 172 } |
OLD | NEW |