diff options
author | Aaron Jacobs <jacobsa@google.com> | 2015-02-06 09:34:00 +1100 |
---|---|---|
committer | Sameer Ajmani <sameer@golang.org> | 2015-02-06 15:15:11 +0000 |
commit | d534621e649a469ca9f9bdb141e2dde4d764b508 (patch) | |
tree | f591fe6ef402af756258e5822f78f41363d3774d | |
parent | 71586c3cf98f806af322c5a361660eb046e00501 (diff) | |
download | net-d534621e649a469ca9f9bdb141e2dde4d764b508.tar.gz |
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>
-rw-r--r-- | context/context.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/context/context.go b/context/context.go index 490245d..449ca32 100644 --- a/context/context.go +++ b/context/context.go @@ -64,11 +64,11 @@ type Context interface { // // Done is provided for use in select statements: // - // // DoSomething calls DoSomethingSlow and returns as soon as + // // CancelableOperation calls UncancelableOperation and returns as soon as // // it returns or ctx.Done is closed. - // func DoSomething(ctx context.Context) (Result, error) { + // func CancelableOperation(ctx context.Context) (Result, error) { // c := make(chan Result, 1) - // go func() { c <- DoSomethingSlow(ctx) }() + // go func() { c <- UncancelableOperation() }() // select { // case res := <-c: // return res, nil |