In ping.go
the printer
runs in a goroutine and the main thread is blocked by fmt.Scanln
. As expected it prints ping, then pong.
In ping2.go
the printer
itself is blocking the main thread. When run it returns ping twice before returning a pong.
$ go run ping.go
ping
pong
ping
pong
^C
$ go run ping2.go
ping
ping
pong
ping
pong