diff options
| author | Carlos C <uldericofilho@gmail.com> | 2016-08-12 12:45:14 +0200 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-09-09 22:50:41 +0000 |
| commit | 1161a19c1ef536f8db2ca7eddf0e424e138e37db (patch) | |
| tree | 822aee6170d460561094463542d036f9983dd046 /src/context/withtimeout_test.go | |
| parent | d817c4ec6d458777537aae3a04201b7182a5f78a (diff) | |
| download | go-1161a19c1ef536f8db2ca7eddf0e424e138e37db.tar.xz | |
context: add examples
Add function level examples to the package.
Partially addresses #16360
Change-Id: I7162aed4e4a969743c19b79c9ffaf9217d2c1c08
Reviewed-on: https://go-review.googlesource.com/26930
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/context/withtimeout_test.go')
| -rw-r--r-- | src/context/withtimeout_test.go | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/src/context/withtimeout_test.go b/src/context/withtimeout_test.go deleted file mode 100644 index a3e8979c8c..0000000000 --- a/src/context/withtimeout_test.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package context_test - -import ( - "context" - "fmt" - "time" -) - -func ExampleWithTimeout() { - // Pass a context with a timeout to tell a blocking function that it - // should abandon its work after the timeout elapses. - ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond) - - select { - case <-time.After(1 * time.Second): - fmt.Println("overslept") - case <-ctx.Done(): - fmt.Println(ctx.Err()) // prints "context deadline exceeded" - } - - // Even though ctx should have expired already, it is good - // practice to call its cancelation function in any case. - // Failure to do so may keep the context and its parent alive - // longer than necessary. - cancel() - - // Output: - // context deadline exceeded -} |
