This is motivated by a few reasons. One, the upstream package has more
examples, and no one should be looking at this old package to learn how
to use it. Seeing an example might make it seem like the scope of the
documentation here is to provide examples, and that there aren't many
of them. Instead of trying to add more examples or maintain the current
one by porting the de-flake enhancement from CL 460999, delete the only
example here.
Second, running 'go fix ./...' causes the 'context' fix to rewrite the
import path of the example from "golang.org/x/net/context" to "context".
That is a false positive in the fix, and I would've liked it fix the
fix, but it only has the AST information at this time, not type info,
so the import path isn't currently available to the check. That means
it can't know when it's running on the golang.org/x/net/context package,
which is the one place it should skip the rewrite.
It seems simpler to just delete the example, and then it becomes
possible to use 'go fix ./...' safely on the entire x/net module.
For golang/go#49506.
Change-Id: I97eba33ca2e1f2960aef8340d8b561639a26ee48
Reviewed-on: https://go-review.googlesource.com/c/net/+/650156
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Since Go 1.7 started including the context package in the core
distribution, this package has been forwarding to the core package's
implementation to the best of its ability. Since type aliases are due
to be included in the Go 1.9 release, use them to forward more
completely.
Change-Id: I97b92cd34b3f4426f565bb3d115f119d3c83a1dd
Reviewed-on: https://go-review.googlesource.com/49020
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
CL 47095 applied a change to ExampleWithTimeout to resolve test
flakiness. This change deviated ExampleWithTimeout further away
from the ExampleWithTimeout in standard library's context package.
There was a minor issue spotted in code review. Instead of attempting
to resolve it here, it's better to use the version of ExampleWithTimeout
from standard library that doesn't have the issue, and reduce
maintenance.
Change-Id: I3da9d7f7c35b33b52635df4c61058cb0b8ae95d9
Reviewed-on: https://go-review.googlesource.com/47212
Run-TryBot: Dmitri Shuralyov <shurcool@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The tree's pretty inconsistent about single space vs double space
after a period in documentation. Make it consistently a single space,
per earlier decisions, and changes in go repository. This means
contributors won't be confused by misleading precedence.
This CL was generated with:
perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])')
on top of copyright headers change in https://golang.org/cl/32878.
Follows https://golang.org/cl/20022.
Change-Id: I821e4a300122b4668aa31e12eaa914db615e5369
Reviewed-on: https://go-review.googlesource.com/32879
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The context tests were flaky under Go 1.6 on Windows. Make them
slower, but make up for the slowness by parallelizing them.
These tests don't run on Go 1.7+ in the subrepo. They were deflaked in
the standard library's context in Go 1.7.
Updates golang/go#11811
Change-Id: I8dc8d9e13e72e87b4444e92d2316dd95bd7d066d
Reviewed-on: https://go-review.googlesource.com/34288
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
CancelFunc was the only part of the context package which didn't
forward nicely with the move from x/net/context to std context.
Use it for Context as well.
Change-Id: Ieff39b10b0783d55d0437c73923053297ed0ea4a
Reviewed-on: https://go-review.googlesource.com/32317
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
The Go 1.4 (and earlier) support for request cancellation is racy and
complicates the implementation of ctxhttp. This change simply inlines
the existing 1.5+ cancellation logic directly, and removes support for
older versions.
Change-Id: I7df9f0648dd0e571366374d079e2976050464ca3
Reviewed-on: https://go-review.googlesource.com/22302
Reviewed-by: David Symonds <dsymonds@golang.org>
Run-TryBot: David Symonds <dsymonds@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
cancelCtx has an embedded sync.Mutex. This change causes an extra
allocation when creating a new timerCtx via WithDeadline, but that seems
minor when compared with better locking discipline. If it turns out to
be a problem, the whole cancelCtx struct can be flattened into timerCtx.
Addresses part of golang/go#14839.
Change-Id: Ie86ed1b63592b521aefde747d5fafcd49ac18178
Reviewed-on: https://go-review.googlesource.com/20840
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
plan9's network deadline & cancelation code is so brittle that it's
not even worth testing this package there. It only results in 10
minute deadlocks and slows down the trybots which should be ~30
seconds, not 10 minutes.
Change-Id: I097a885ae5887f0ecf357611aa7fae8885e18e05
Reviewed-on: https://go-review.googlesource.com/18578
Reviewed-by: Chris Broadfoot <cbro@golang.org>
This is necessary for cleanup of any goroutine that blocks on
ctx.Done(), as is done in e.g. propagateCancel in context.go. It is
already specified for WithTimeout and WithDeadline, whose descriptions I
have simplified here.
Change-Id: I6b30605decb8c0b7c1296c3f8852f9ad305ad4b7
Reviewed-on: https://go-review.googlesource.com/5022
Reviewed-by: Sameer Ajmani <sameer@golang.org>
The current example leaks the DoSomethingSlow goroutine for an
arbitrarily long time. In a real server, that can lead to an
out-of-memory failure during events such as network outages; a
more careful version of that example would be too long for a
simple package doc.
Fortunately, there are other short, common patterns using Done
that don't leak and don't require a lot of explanation. Let's
use one of those instead.
Change-Id: I0ad0c6121d06b757a397e0e71be9e01ccfd75f77
Reviewed-on: https://go-review.googlesource.com/4490
Reviewed-by: Andrew Gerrand <adg@golang.org>
The point of the DoSomething function is to protect the user from
DoSomethingSlow, which presumably doesn't support returning early upon
cancellation and deadline expiration (or else DoSomething wouldn't need
to exist).
Since most of the point of the Context object is communicating deadline
and cancellation, it is misleading for DoSomethingSlow to accept a
context object. A function like DoSomething is only likely to be written
when wrapping other code that doesn't properly support contexts.
Change-Id: Ibdef5b7ed71387ba6a09179ef2f911fc3f98e40a
Reviewed-on: https://go-review.googlesource.com/3902
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Recent runtime changes mean that these are stored indirectly, requiring additional allocation.
LGTM=adonovan
R=rsc, bradfitz, adonovan
CC=golang-codereviews
https://golang.org/cl/148590043
It seems like it was meant to be this way. There was already a for loop, but then it made a recursive call instead.
LGTM=sameer
R=golang-codereviews, sameer
CC=golang-codereviews
https://golang.org/cl/113540044
to construct the context left-to-right. External implementations of the
Context interface may break the chain, but establishing this pattern now
may encourage them to do the right thing.
LGTM=bcmills
R=bcmills
CC=golang-codereviews
https://golang.org/cl/116430044
WithCancel, and WithTimeout to use different concrete types. Update the
tests and documentation.
This change reduces the size of context structs, reduces the number of
allocations (see TestAllocs) and removes unnecessary pointers from the
heap, such as the timer field for non-timer contexts.
IMPORTANT: I've removed the code in these functions that handles nil Context parameters. Passing a nil parent Context will now cause a panic.
LGTM=bcmills
R=bcmills, crawshaw
CC=adonovan, golang-codereviews, rsc
https://golang.org/cl/116400043
This is the first step in splitting the various context implementations
into smaller types.
Add a test that creates a large, random stack of Contexts and tests that
they work properly.
LGTM=crawshaw
R=crawshaw
CC=golang-codereviews
https://golang.org/cl/115350044
makes the Context interface dependent only on standard packages, which
means types in other packages can implement this interface without
depending on go.net/context.
Remove the NewKey function and add examples showing how to use
unexported types to avoid key collisions. This is the same model used
by http://www.gorillatoolkit.org/pkg/context, except we associate values
with a specific Context instead of storing them in a package-level map.
LGTM=crawshaw
R=golang-codereviews, crawshaw, dsymonds
CC=golang-codereviews, rsc
https://golang.org/cl/104480044