summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/net/context/withtimeout_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/net/context/withtimeout_test.go')
-rw-r--r--vendor/golang.org/x/net/context/withtimeout_test.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/vendor/golang.org/x/net/context/withtimeout_test.go b/vendor/golang.org/x/net/context/withtimeout_test.go
index a6754dc36..e6f56691d 100644
--- a/vendor/golang.org/x/net/context/withtimeout_test.go
+++ b/vendor/golang.org/x/net/context/withtimeout_test.go
@@ -11,16 +11,21 @@ import (
"golang.org/x/net/context"
)
+// This example passes a context with a timeout to tell a blocking function that
+// it should abandon its work after the timeout elapses.
func ExampleWithTimeout() {
// Pass a context with a timeout to tell a blocking function that it
// should abandon its work after the timeout elapses.
- ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond)
+ ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
+ defer cancel()
+
select {
- case <-time.After(200 * time.Millisecond):
+ case <-time.After(1 * time.Second):
fmt.Println("overslept")
case <-ctx.Done():
fmt.Println(ctx.Err()) // prints "context deadline exceeded"
}
+
// Output:
// context deadline exceeded
}