Goroutines
package main import ( "fmt" "time" ) /* * This function prints messages in a loop with a short delay between. */ func printer(count int) { fmt.Println("Printer start...") for i := 1; i <= count; i++ { fmt.Println("Printer", i) time.Sleep(400*time.Millisecond) } fmt.Println("Printer end...") } /* * The main also prints messages with a short delay, but first first up * the printer function to run in parallel, so both run at the same time. */ func main() { fmt.Println("Main start...") go printer(8) for i := 1; i <= 5; i++ { fmt.Println("Main", i) time.Sleep(710*time.Millisecond) } fmt.Println("Main end...") }