diff --git a/eBook/11.1.md b/eBook/11.1.md index cf57d5a..edbfa59 100644 --- a/eBook/11.1.md +++ b/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 个方法。 diff --git a/eBook/14.17.md b/eBook/14.17.md index 34ced51..d5120cb 100644 --- a/eBook/14.17.md +++ b/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) diff --git a/eBook/examples/chapter_14/channel_block.go b/eBook/examples/chapter_14/channel_block.go index 510afcb..78df75c 100644 --- a/eBook/examples/chapter_14/channel_block.go +++ b/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 } }