2020
12-22
12-22
浅谈golang for 循环中使用协程的问题
两个例子packagemainimport("fmt""time")funcProcess1(tasks[]string){for_,task:=rangetasks{//启动协程并发处理任务gofunc(){fmt.Printf("Workerstartprocesstask:%s\n",task)}()}}funcmain(){tasks:=[]string{"1","2","3","4","5"}Process1(tasks)time.Sleep(2*time.Second)}结果:第一次运行Workerstartprocesstask:3Workerstartprocesstask:4Workerstartprocesstask:...
继续阅读 >