If you remove the time.Sleep
you don't give the say("world")
goroutine a chance to run. The goroutine scheduler is not preemptive. Your goroutines have to give up control before another goroutine will run. One way to give up control is to run time.Sleep
.
If you take out the time.Sleep
from the say
function then the primary goroutine runs 5 times without giving up control to the secondary goroutine and then when the primary goroutine returns from say
the program exits because there is nothing to keep the program alive.