mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-08-09 16:42:26 +00:00
fmr code
This commit is contained in:
@@ -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,來達成處理其它輸入或輸出事件時超時和取消的邏輯。我們會在下一節中看到一個例子。
|
||||
|
Reference in New Issue
Block a user