29 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
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
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
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
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
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
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
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
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
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
Sameer Ajmani
f572974747 go.net/context: define the Context type, which supports propagating
deadlines, cancellation, and other values across APIs and between
processes.

LGTM=crawshaw
R=rsc, crawshaw
CC=bradfitz, golang-codereviews
https://golang.org/cl/99330045
2014-05-16 16:11:29 -04:00