goroutine

A function running concurrently with the rest of a Go program, started by putting the go keyword before a call.

In more detail

Goroutines are very cheap, so a tool can start one per target. The caller carries on immediately, and when main returns the program exits whether or not goroutines have finished, so wait for them with a sync.WaitGroup or a channel. The Go runtime schedules them across the machine's processor cores.

Example

go func() {
	defer wait.Done()
	fmt.Println("worker finished")
}()

Related terms

Taught in

References