Parcourir la source

fix spelling error and some improper demo (#807)

Co-authored-by: zhouzilong.luke <[email protected]>
Co-authored-by: Joe Chen <[email protected]>
Luke Zhou il y a 4 ans
Parent
commit
dc86a917a6
3 fichiers modifiés avec 14 ajouts et 4 suppressions
  1. 1 1
      eBook/11.1.md
  2. 1 1
      eBook/14.17.md
  3. 12 2
      eBook/examples/chapter_14/channel_block.go

+ 1 - 1
eBook/11.1.md

@@ -18,7 +18,7 @@ type Namer interface {
 
 上面的 `Namer` 是一个 **接口类型**。
 
-(按照约定,只包含一个方法的)接口的名字由方法名加 `[e]r` 后缀组成,例如 `Printer`、`Reader`、`Writer`、`Logger`、`Converter` 等等。还有一些不常用的方式(当后缀 `er` 不合适时),比如 `Recoverable`,此时接口名以 `able` 结尾,或者以 `I` 开头(像 `.NET` 或 `Java` 中那样)。
+(按照约定,只包含一个方法的)接口的名字由方法名加 `er` 后缀组成,例如 `Printer`、`Reader`、`Writer`、`Logger`、`Converter` 等等。还有一些不常用的方式(当后缀 `er` 不合适时),比如 `Recoverable`,此时接口名以 `able` 结尾,或者以 `I` 开头(像 `.NET` 或 `Java` 中那样)。
 
 Go 语言中的接口都很简短,通常它们会包含 0 个、最多 3 个方法。
 

+ 1 - 1
eBook/14.17.md

@@ -69,5 +69,5 @@ Person - name is: Smith Bill - salary is: 4000.25
 
 - [目录](directory.md)
 - 上一节:[对Go协程进行基准测试](14.16.md)
-- 下一:[网络,模板和网页应用](15.0.md)
+- 下一:[网络,模板和网页应用](15.0.md)
  

+ 12 - 2
eBook/examples/chapter_14/channel_block.go

@@ -1,15 +1,25 @@
 package main
 
-import "fmt"
+import (
+	"fmt"
+	"time"
+)
+
+var cnt = 0
 
 func main() {
 	ch1 := make(chan int)
 	go pump(ch1)       // pump hangs
 	fmt.Println(<-ch1) // prints only 0
+
+	time.Sleep(time.Second)
+	fmt.Println(cnt) // prints 1
+
 }
 
 func pump(ch chan int) {
 	for i := 0; ; i++ {
-		ch <- i
+		ch <- i // the channel will be block due to lack of consumer
+		cnt++   // this code will only execute once
 	}
 }