浏览代码

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>
Aaron Jacobs 11 年之前
父节点
当前提交
d534621e64
共有 1 个文件被更改,包括 3 次插入3 次删除
  1. 3 3
      context/context.go

+ 3 - 3
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