mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:33:04 +08:00
Update 14.2.md (#542)
返回的通道的传递类型应为 item. 方法定义的返回类型, 应和方法体中return的一致, 即make(chan item).
This commit is contained in:
@@ -489,7 +489,7 @@ func suck(ch chan int) {
|
|||||||
这个模式用到了后边14.6章示例 [producer_consumer.go](exercises/chapter_14/producer_consumer.go) 的生产者-消费者模式,通常,需要从包含了地址索引字段 items 的容器给通道填入元素。为容器的类型定义一个方法 `Iter()`,返回一个只读的通道(参见第 [14.2.8](14.2.md#1428-实现并行的-for-循环) 节)items,如下:
|
这个模式用到了后边14.6章示例 [producer_consumer.go](exercises/chapter_14/producer_consumer.go) 的生产者-消费者模式,通常,需要从包含了地址索引字段 items 的容器给通道填入元素。为容器的类型定义一个方法 `Iter()`,返回一个只读的通道(参见第 [14.2.8](14.2.md#1428-实现并行的-for-循环) 节)items,如下:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (c *container) Iter () <- chan items {
|
func (c *container) Iter () <- chan item {
|
||||||
ch := make(chan item)
|
ch := make(chan item)
|
||||||
go func () {
|
go func () {
|
||||||
for i:= 0; i < c.Len(); i++{ // or use a for-range loop
|
for i:= 0; i < c.Len(); i++{ // or use a for-range loop
|
||||||
|
Reference in New Issue
Block a user