1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-28 23:42:21 +00:00

Merge pull request #90 from fuwensun/fix-a

ch-1-06-部分例子代码统一用tab缩进
This commit is contained in:
Xargin 2018-06-15 23:44:47 +08:00 committed by GitHub
commit d52c5dd8e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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