mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:21:38 +08:00
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:
@@ -18,7 +18,7 @@ type Namer interface {
|
|||||||
|
|
||||||
上面的 `Namer` 是一个 **接口类型**。
|
上面的 `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 个方法。
|
Go 语言中的接口都很简短,通常它们会包含 0 个、最多 3 个方法。
|
||||||
|
|
||||||
|
@@ -69,5 +69,5 @@ Person - name is: Smith Bill - salary is: 4000.25
|
|||||||
|
|
||||||
- [目录](directory.md)
|
- [目录](directory.md)
|
||||||
- 上一节:[对Go协程进行基准测试](14.16.md)
|
- 上一节:[对Go协程进行基准测试](14.16.md)
|
||||||
- 下一节:[网络,模板和网页应用](15.0.md)
|
- 下一章:[网络,模板和网页应用](15.0.md)
|
||||||
|
|
||||||
|
@@ -1,15 +1,25 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cnt = 0
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ch1 := make(chan int)
|
ch1 := make(chan int)
|
||||||
go pump(ch1) // pump hangs
|
go pump(ch1) // pump hangs
|
||||||
fmt.Println(<-ch1) // prints only 0
|
fmt.Println(<-ch1) // prints only 0
|
||||||
|
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
fmt.Println(cnt) // prints 1
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func pump(ch chan int) {
|
func pump(ch chan int) {
|
||||||
for i := 0; ; i++ {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user