fix spelling error and some improper demo (#807)

Co-authored-by: zhouzilong.luke <zhouzilong.luke@bytedance.com>
Co-authored-by: Joe Chen <jc@unknwon.io>
This commit is contained in:
Luke Zhou
2021-10-23 11:49:46 +08:00
committed by GitHub
parent e719589582
commit dc86a917a6
3 changed files with 14 additions and 4 deletions

View File

@@ -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 个方法。

View File

@@ -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)

View File

@@ -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
}
}