ch8: fix code format

This commit is contained in:
chai2010
2016-01-21 10:39:06 +08:00
parent 0b5ec941ed
commit b1730821fe
13 changed files with 393 additions and 404 deletions

View File

@@ -6,9 +6,8 @@ Channels也可以用於將多個goroutine鏈接在一起一個Channels的輸
第一個goroutine是一個計數器用於生成0、1、2、……形式的整數序列然後通過channel將該整數序列發送給第二個goroutine第二個goroutine是一個求平方的程序對收到的每個整數求平方然後將平方後的結果通過第二個channel發送給第三個goroutine第三個goroutine是一個打印程序打印收到的每個整數。爲了保持例子清晰我們有意選擇了非常簡單的函數當然三個goroutine的計算很簡單在現實中確實沒有必要爲如此簡單的運算構建三個goroutine。
<u><i>gopl.io/ch8/pipeline1</i></u>
```Go
gopl.io/ch8/pipeline1
func main() {
naturals := make(chan int)
squares := make(chan int)
@@ -65,9 +64,8 @@ go func() {
在下面的改進中我們的計數器goroutine隻生成100個含數字的序列然後關閉naturals對應的channel這將導致計算平方數的squarer對應的goroutine可以正常終止循環併關閉squares對應的channel。在一個更複雜的程序中可以通過defer語句關閉對應的channel。最後主goroutine也可以正常終止循環併退出程序。
<u><i>gopl.io/ch8/pipeline2</i></u>
```Go
gopl.io/ch8/pipeline2
func main() {
naturals := make(chan int)
squares := make(chan int)