1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 20:52:22 +00:00

ch-1-06-部分例子代码统一用tab缩进

This commit is contained in:
sfw 2018-06-15 22:29:52 +08:00
parent 7218960bf0
commit 7a64a27beb

View File

@ -513,23 +513,23 @@ Go语言中不同Goroutine之间主要依靠管道进行通信和同步。要同
基于`select`实现的管道的超时判断: 基于`select`实现的管道的超时判断:
```go ```go
select { select {
case v := <-in: case v := <-in:
fmt.Println(v) fmt.Println(v)
case <-time.After(time.Second): case <-time.After(time.Second):
return // 超时 return // 超时
} }
``` ```
通过`select``default`分支实现非阻塞的管道发送或接收操作: 通过`select``default`分支实现非阻塞的管道发送或接收操作:
```go ```go
select { select {
case v := <-in: case v := <-in:
fmt.Println(v) fmt.Println(v)
default: default:
// 没有数据 // 没有数据
} }
``` ```
通过`select`来阻止`main`函数退出: 通过`select`来阻止`main`函数退出: