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

Side by Side Diff: common/gcloud/pubsub/subscriber/subscriber.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/gcloud/pubsub/ackbuffer/ackbuffer_test.go ('k') | common/meter/config.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 subscriber 5 package subscriber
6 6
7 import ( 7 import (
8 "sync" 8 "sync"
9 "time" 9 "time"
10 10
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // sleep. This is a simple method to obtain the desired effect of avoiding 157 // sleep. This is a simple method to obtain the desired effect of avoiding
158 // pointless burst Pub/Sub spam when the service has nothing useful to offer. 158 // pointless burst Pub/Sub spam when the service has nothing useful to offer.
159 func (s *Subscriber) noDataSleep(c context.Context) { 159 func (s *Subscriber) noDataSleep(c context.Context) {
160 s.noDataMu.Lock() 160 s.noDataMu.Lock()
161 defer s.noDataMu.Unlock() 161 defer s.noDataMu.Unlock()
162 162
163 d := s.NoDataDelay 163 d := s.NoDataDelay
164 if d <= 0 { 164 if d <= 0 {
165 d = DefaultNoDataDelay 165 d = DefaultNoDataDelay
166 } 166 }
167 » cancellableSleep(c, d) 167 » clock.Sleep(c, d)
168 } 168 }
169
170 // cancellableSleep sleeps, returning either when the sleep duration has expired
171 // or the supplied context has been canceled.
172 func cancellableSleep(c context.Context, delay time.Duration) {
173 // Sleep for "delay", stopping early if our Context is canceled.
174 select {
175 case <-clock.After(c, delay):
176 break
177
178 case <-c.Done():
179 break
180 }
181 }
OLDNEW
« no previous file with comments | « common/gcloud/pubsub/ackbuffer/ackbuffer_test.go ('k') | common/meter/config.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698