52 Commits

Author SHA1 Message Date
Damien Neil
07cefd8a6b context: deprecate
Long superseded by the stdlib's context package.

Fixes golang/go#49506

Change-Id: I16e9a1275a7370cd78d11180f608ae28ecdce143
Reviewed-on: https://go-review.googlesource.com/c/net/+/719060
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2025-11-08 12:28:41 -08:00
Alan Donovan
b800b2045a context: add //go:fix inline annotation to Context et al
Updates golang/go#73605

Change-Id: Ib9d23a2eaa35f6099e6e42857b35f717a0a2f00d
Reviewed-on: https://go-review.googlesource.com/c/net/+/691075
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
2025-09-04 09:58:34 -07:00
Dmitri Shuralyov
447f458ae0 context: delete lone example
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>
2025-02-18 09:30:11 -08:00
Dmitri Shuralyov
918d64e8e6 context: delete dead code, sync docs with upstream context package
The go directive is now at 1.23.0, so the go1.7 and go1.9 build
constraints are guaranteed to always be satisfied, and their inverse
will never be satisfied. Delete all the dead code and merge everything
that's left in a single context.go file. Also update docs to match the
upstream context package.

For golang/go#49506.

Change-Id: I317550767838a93af2c2d3dbc7b61f2e37e6fe1c
Reviewed-on: https://go-review.googlesource.com/c/net/+/650155
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-02-18 09:28:57 -08:00
Damien Neil
c1f5833288 all: replace deprecated io/ioutil calls
The io/ioutil package's features were moved to
the io and os packages in Go 1.16.

x/net depends on Go 1.18. Drop ioutil calls,
so gopls doesn't warn about them.

Change-Id: Ibdb576d94f250808ae285aa142e2fd41e7e9afc9
Reviewed-on: https://go-review.googlesource.com/c/net/+/586244
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-05-21 19:59:00 +00:00
Dmitri Shuralyov
d23d9bc549 all: update go directive to 1.18
Done with:

go get go@1.18
go mod tidy
go fix ./...

Using go1.21.3.

With a manual change to keep golang.org/x/net/context testing itself,
not context in the standard library.

For golang/go#60268.

Change-Id: I00682bf7cf1e3ba4370e2a3e7f63dc245b294a36
Reviewed-on: https://go-review.googlesource.com/c/net/+/534241
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>
2023-10-11 21:58:12 +00:00
cui fliter
bea034e7d5 all: remove redundant type conversion
Change-Id: I37550b85567abd2f5b422e742fcea9b26fd80f2b
GitHub-Last-Rev: b2e840379d
GitHub-Pull-Request: golang/net#148
Reviewed-on: https://go-review.googlesource.com/c/net/+/428937
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-09 16:43:09 +00:00
Russ Cox
290c469a71 all: gofmt
Gofmt to update doc comments to the new formatting.

For golang/go#51082.

Change-Id: Iae68a9cd600060577271575e893ecb23bed1e509
Reviewed-on: https://go-review.googlesource.com/c/net/+/399599
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-04-12 02:06:05 +00:00
Russ Cox
5f55cee0dc all: go fmt ./...
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Not strictly necessary but will avoid spurious changes
as files are edited.

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: I5b2b7d93424e828a3c5f76ae3f30ab825aca388e
Reviewed-on: https://go-review.googlesource.com/c/net/+/294371
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-20 03:31:24 +00:00
Dmitri Shuralyov
88d92db4c5 context/ctxhttp: remove Go 1.6 support, use std context
Fixes golang/go#21358

Change-Id: I8f8653df3c1e3c86cc8515a78509a8af03160944
Reviewed-on: https://go-review.googlesource.com/c/149277
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-13 16:55:02 +00:00
Francisco Rojas
5561cd9b43 context: mention standard library version in package comment
Fixes golang/go#22322

Change-Id: I1f0c62ce1c247b583de51faef8722d07e627b441
Reviewed-on: https://go-review.googlesource.com/72570
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-23 17:40:46 +00:00
Rhys Hiltner
b3756b4b77 context: use Go 1.9 type alias for CancelFunc and Context
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>
2017-07-16 17:46:42 +00:00
Dmitri Shuralyov
1f9224279e context: sync ExampleWithTimeout with std lib context
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>
2017-06-29 17:10:32 +00:00
Brad Fitzpatrick
c81e7f25cb context: deflake example
Got a trybot failure in
https://storage.googleapis.com/go-build-log/8aee0b8b/linux-amd64_38d0be3e.log

Change-Id: I867a658968a0088c9f3f76ff235816e4179f0bec
Reviewed-on: https://go-review.googlesource.com/47095
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2017-06-29 03:33:46 +00:00
haya14busa
349ad30abd context/ctxhttp: close httptest server
Change-Id: Ic8192f74337e021a5d72feb07b9648619d778235
Reviewed-on: https://go-review.googlesource.com/36673
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-09 17:05:06 +00:00
Dmitri Shuralyov
357296a763 all: single space after period
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>
2017-02-01 21:02:21 +00:00
Brad Fitzpatrick
cfae461ced context: deflake tests under Go 1.6
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>
2016-12-13 03:21:26 +00:00
Brad Fitzpatrick
158696dc0d Revert "context: use Go 1.8 type alias for CancelFunc and Context"
This reverts commit dffc95cbb4.

Aliases aren't going into Go 1.8. See:
https://github.com/golang/go/issues/16339#issuecomment-258527920

Updates #16339

Change-Id: Ie37e37349db596a89b4944179ab87b6f0577c826
Reviewed-on: https://go-review.googlesource.com/32753
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-11-04 20:15:55 +00:00
Brad Fitzpatrick
dffc95cbb4 context: use Go 1.8 type alias for CancelFunc and Context
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>
2016-10-28 22:21:43 +00:00
Ian Lance Taylor
45b61eaf18 context/ctxhttp: if context is canceled, return its error
This preserves the promise that Do will return the context's error.

Fixes golang/go#16381

Change-Id: I0db49b175736a695199b38819b4ff97b83d9c5ed
Reviewed-on: https://go-review.googlesource.com/24977
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-07-16 21:44:27 +00:00
Brad Fitzpatrick
f841c39de7 context/ctxhttp: add a specialized minimal version for Go 1.7
Change-Id: Ib174b984184191d803364c684070346a105ef4b5
Reviewed-on: https://go-review.googlesource.com/24620
Reviewed-by: Chris Broadfoot <cbro@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Dave Day <djd@golang.org>
2016-07-07 22:37:29 +00:00
Ian Lance Taylor
2a35e68658 context: correct spelling of TODO in comment
Change-Id: I62bfc730643cb0756fc67f3c5cf73029b75c07bb
Reviewed-on: https://go-review.googlesource.com/22884
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-05-06 21:07:50 +00:00
Brad Fitzpatrick
1aafd77e1e context: fix doc typo
Fixes golang/go#15449

Change-Id: Ib4802dc1d9208abc17ef31212d49f03f4f4ed3d1
Reviewed-on: https://go-review.googlesource.com/22494
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-27 15:28:33 +00:00
Dave Day
815d315ead context/ctxhttp: remove pre-Go 1.5 support
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>
2016-04-21 00:36:51 +00:00
David Symonds
fb93926129 context: bump gccgo-specific alloc limit for WithTimeout test.
9d8ef8d caused an extra allocation for gccgo.

Change-Id: I6568d84009882103ec4767546599afa20c54c480
Reviewed-on: https://go-review.googlesource.com/21940
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-12 22:56:35 +00:00
Brad Fitzpatrick
afc22ee913 context: implement in terms of the standard library for Go 1.7+
See https://golang.org/cl/20346

Updates golang/go#14660

Change-Id: Ia974e70cdcb240ae1df0018a07595c4d1dcd422a
Reviewed-on: https://go-review.googlesource.com/20347
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-05 00:08:57 +00:00
David Symonds
9d8ef8d73b context: Uniformly pass cancelCtx by pointer.
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>
2016-03-20 20:34:16 +00:00
Brad Fitzpatrick
a4bbce9fca context/ctxhttp: fix data race in tests
Change-Id: If36de4de2c4fac6767aa5490e6f3d8c15531dda6
Reviewed-on: https://go-review.googlesource.com/20275
Reviewed-by: Dave Day <djd@golang.org>
2016-03-06 22:39:36 +00:00
Brad Fitzpatrick
f315505cf3 net/context/ctxhttp: fix case where Body could leak and not be closed
Fixes golang/go#14065

Change-Id: Ic19a0f740cddced8fb782f65cea14da383b047b1
Reviewed-on: https://go-review.googlesource.com/18802
Reviewed-by: Olivier Poitrey <rs@rhapsodyk.net>
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
Reviewed-by: Chris Broadfoot <cbro@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-26 03:35:23 +00:00
Brad Fitzpatrick
e82aa266f2 context/ctxhttp: don't test on plan9
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>
2016-01-13 22:11:00 +00:00
Dave Day
3b90a77d28 context/ctxhttp: allow cancellation after Do returns
Fixes #13325.

Change-Id: I17f35232cd0ea43e50ea12db09272195789426e9
Reviewed-on: https://go-review.googlesource.com/18188
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-05 05:09:10 +00:00
Aiden Scandella
1d9fd3b833 context: fix typo in TODO documentation
This fixes an incorrect contraction, and makes it easier to read.

Change-Id: I8b88b6f54df25c4c36e00e6fbe77b3c32e518e12
Reviewed-on: https://go-review.googlesource.com/16895
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-11-14 12:21:28 +00:00
Sameer Ajmani
96feaeba77 context: attempt to deflake TestLayersTimeout with timer padding.
Fixes #11512.

Change-Id: Iaf98ec25fb16a2409c1ff7d110afa6477267d3e1
Reviewed-on: https://go-review.googlesource.com/13643
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-10-19 16:59:31 +00:00
Chris Broadfoot
1bc0720082 context: Add ctxhttp package.
ctxhttp provides helper functions for performing context-aware HTTP
requests.

Fixes golang/go#11904

Change-Id: Ib9d2fef48953dbb52f0a70e1ed49ea7fe12b7801
Reviewed-on: https://go-review.googlesource.com/12755
Reviewed-by: David Symonds <dsymonds@golang.org>
Reviewed-by: Aaron Jacobs <jacobsa@google.com>
Reviewed-by: Dave Day <djd@golang.org>
2015-08-05 04:30:13 +00:00
David Symonds
76c2dd9e94 context: Increase a gccgo-specific alloc limit.
Change-Id: I526ecbab37b68d689ddffa60c2e231099c1477b6
Reviewed-on: https://go-review.googlesource.com/13056
Reviewed-by: Dave Day <djd@golang.org>
2015-08-04 00:20:08 +00:00
Aaron Jacobs
b6fdb7d8a4 context: Be clear that users must cancel the result of WithCancel.
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>
2015-02-20 17:22:32 +00:00
Bryan C. Mills
59b0df9b1f net/context: Don't leak goroutines in Done example.
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>
2015-02-12 17:18:52 +00:00
Damien Neil
f090b05f9b context: fix removal of cancelled timer contexts from parent
Change-Id: Iee673c97e6a3b779c3d8ba6bb1b5f2b2e2032b86
Reviewed-on: https://go-review.googlesource.com/3911
Reviewed-by: Sameer Ajmani <sameer@golang.org>
2015-02-09 17:53:57 +00:00
Aaron Jacobs
d534621e64 net/context: Don't accept a context in the DoSomethingSlow example.
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>
2015-02-06 15:15:11 +00:00
David Symonds
8aa6e209cb net: add import comments.
Change-Id: Ifab0fdaec1d810d268b7c19ad30f476802203b37
2014-12-09 14:17:11 +11:00
David Symonds
53bb7518de context: Fix WithValue example code.
LGTM=adg
R=adg
CC=golang-codereviews, sameer
https://golang.org/cl/169540043
2014-11-14 14:29:31 +11:00
Andrew Gerrand
fbe893ddcd go.net: use golang.org/x/... import paths
LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/167030043
2014-11-10 09:04:43 +11:00
Sameer Ajmani
3ffb8fd19b context: fix TestAllocs to account for ints in interfaces
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
2014-10-09 13:51:22 -04:00
Andrew Bursavich
84f8955a88 context: make parentCancelCtx iterative
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
2014-08-11 16:57:02 -04:00
Sameer Ajmani
9c40a72a07 context: provide String methods. The Strings show the functions called
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
2014-08-01 09:28:31 -04:00
Sameer Ajmani
983e15c919 context: fix small leak introduced by reordering.
LGTM=bcmills
R=bcmills
CC=golang-codereviews
https://golang.org/cl/116420045
2014-07-30 13:03:32 -04:00
Sameer Ajmani
a67aa99698 go.net/context: split the implementations of Background, WithValue,
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
2014-07-30 12:14:59 -04:00
Sameer Ajmani
a1f3609ec9 go.net/context: define an emptyCtx type for Background and TODO.
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
2014-07-29 14:21:02 -04:00
Sameer Ajmani
8734c4524d go.net/context: update some comments, add a TODO.
Use consistent spelling.

LGTM=bcmills
R=bcmills
CC=golang-codereviews
https://golang.org/cl/117170044
2014-07-24 15:54:48 -04:00
Sameer Ajmani
bf13cf4eb0 go.net/context: remove the Key type; replace it with interface{}. This
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
2014-07-10 14:57:25 -04:00