Skip to content

Commit

Permalink
net/context: Don't accept a context in the DoSomethingSlow example.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jacobsa authored and Sajmani committed Feb 6, 2015
1 parent 71586c3 commit d534621
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d534621

Please sign in to comment.