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

Side by Side Diff: common/clock/cancelSleep.go

Issue 1679023005: Add Context cancellation to clock. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: 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 | « no previous file | common/clock/cancelSleep_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 "time"
9
10 "golang.org/x/net/context"
11 )
12
13 // CancelSleep sleeps the current goroutine (see time.Sleep).
14 //
15 // If the supplied Context is canceled prior to the specified duration,
16 // CancelSleep will return the Context's error. If the sleep completes
17 // naturally, it will return nil.
18 func CancelSleep(c context.Context, d time.Duration) error {
iannucci 2016/02/09 20:41:10 (discussed offline) let's just make normal Sleep (
Vadim Sh. 2016/02/09 21:11:37 I'd prefer to keep CancelSleep. clock package is m
19 select {
20 case <-c.Done():
21 return c.Err()
22
23 case <-After(c, d):
24 // For determinism, prefer context cancellation over full sleep.
25 select {
26 case <-c.Done():
27 return c.Err()
28 default:
29 break
30 }
31 return nil
32 }
33 }
OLDNEW
« no previous file with comments | « no previous file | common/clock/cancelSleep_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698