jjzjj

resultsChan

全部标签

concurrency - 戈朗 : Producer/Consumer concurrency model but with serialized results

funcmain(){jobs:=[]Job{job1,job2,job3}numOfJobs:=len(jobs)resultsChan:=make(chan*Result,numOfJobs)jobChan:=make(chan*job,numOfJobs)goconsume(numOfJobs,jobChan,resultsChan)fori:=0;i在上面的示例中,作业被推送到jobChan中,goroutines将其从jobChan中拉出并并发执行作业并将结果推送到resultsChan中。然后我们将从resultsChan中提取结果。问题一:在我的代码中,没有序列化/线性化