Why does fmt.Println inside a goroutine not print a line?

后端 未结 4 955
野趣味
野趣味 2020-11-28 07:10

I have the following code:

package main

import \"net\"
import \"fmt\"
import \"bufio\"

func main() {
    conn, _ := net.Dial(\"tcp\", \"irc.freenode.net:66         


        
4条回答
  •  庸人自扰
    2020-11-28 07:39

    Another common way to "wait for a goroutines end", is using WaitGroup: http://golang.org/pkg/sync/#WaitGroup . You can use waitGroup.Add(1) for each started goroutine, then use waitGroup.Done() in each goroutine after it finishes. In the main function you can use waitGroup.Wait() and this will wait until waitGroup.Done() has been called for each added goroutine.

提交回复
热议问题