diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-03-08 00:07:18 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-04-05 00:08:50 +0000 |
| commit | 9db7ef561462606085759a2f8a93b7224fdfd2fc (patch) | |
| tree | 7d5947a4d1f4d03b737cf0e3fb8c270dfb3cfee9 /src/context/withtimeout_test.go | |
| parent | 0c71e293b57b0b2fbfa63d0fbf364b1771b6ee6e (diff) | |
| download | go-9db7ef561462606085759a2f8a93b7224fdfd2fc.tar.xz | |
context: add the context package from golang.org/x/net/context
This copies the golang.org/x/net/context package to the standard library.
It is imported from the x/net repo's git rev 1d9fd3b8333e (the most
recent modified to x/net/context as of 2016-03-07).
The corresponding change to x/net/context is in https://golang.org/cl/20347
Updates #14660
Change-Id: Ida14b1b7e115194d6218d9ac614548b9f41641cc
Reviewed-on: https://go-review.googlesource.com/20346
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/context/withtimeout_test.go')
| -rw-r--r-- | src/context/withtimeout_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/context/withtimeout_test.go b/src/context/withtimeout_test.go new file mode 100644 index 0000000000..3ab6fc347f --- /dev/null +++ b/src/context/withtimeout_test.go @@ -0,0 +1,25 @@ +// 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, _ := context.WithTimeout(context.Background(), 100*time.Millisecond) + select { + case <-time.After(200 * time.Millisecond): + fmt.Println("overslept") + case <-ctx.Done(): + fmt.Println(ctx.Err()) // prints "context deadline exceeded" + } + // Output: + // context deadline exceeded +} |
