소스 검색

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