go-zhenai-spider
                                
                                 go-zhenai-spider copied to clipboard
                                
                                    go-zhenai-spider copied to clipboard
                            
                            
                            
                        一个语法上的疑问
https://github.com/jason-wj/go-zhenai-spider/blob/7dba97719a53f98897471f11b2e3918bfabaa7be/src/crawler/engine/concurrent.go#L40-L43 你好,我也看了这套教程,这里我有点疑问,因为这里是开了 goroutine, 会不会有可能循环执行完了,然后轮到 goroutine 执行时使用了错误的 item 值?
https://github.com/jason-wj/go-zhenai-spider/blob/7dba97719a53f98897471f11b2e3918bfabaa7be/src/crawler/engine/concurrent.go#L40-L43
你好,我也看了这套教程,这里我有点疑问,因为这里是开了goroutine,会不会有可能循环执行完了,然后轮到goroutine执行时使用了错误的项值?
是会有问题的,建议改成这样子:
for _, i := range result.Items {
    go func(result.Items) {
        e.ItemChan <- result.Items[i]
    }(i)
}