Skip to content

Commit

Permalink
fix spelling error and some improper demo (#807)
Browse files Browse the repository at this point in the history
Co-authored-by: zhouzilong.luke <zhouzilong.luke@bytedance.com>
Co-authored-by: Joe Chen <jc@unknwon.io>
  • Loading branch information
3 people authored Oct 23, 2021
1 parent e719589 commit dc86a91
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion eBook/11.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 个方法。

Expand Down
2 changes: 1 addition & 1 deletion eBook/14.17.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

14 changes: 12 additions & 2 deletions eBook/examples/chapter_14/channel_block.go
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit dc86a91

Please sign in to comment.