This commit is contained in:
chai2010
2016-01-02 21:17:21 +08:00
parent 8772a9c000
commit ba03c527c0
17 changed files with 63 additions and 29 deletions

View File

@@ -109,7 +109,7 @@ Tick函數挺方便但是隻有當程序整個生命週期都需要這個時
```go
ticker := time.NewTicker(1 * time.Second)
<-ticker.C // receive from the ticker's channel
<-ticker.C // receive from the ticker's channel
ticker.Stop() // cause the ticker's goroutine to terminate
```
@@ -126,6 +126,7 @@ default:
// do nothing
}
```
channel的零值是nil。也許會讓你覺得比較奇怪nil的channel有時候也是有一些用處的。因爲對一個nil的channel發送和接收操作會永遠阻塞在select語句中操作nil的channel永遠都不會被select到。
這使得我們可以用nil來激活或者禁用case來達成處理其它輸入或輸出事件時超時和取消的邏輯。我們會在下一節中看到一個例子。