Goroutines and Concurrency
Prefix a function call with go to run it as a goroutine. main must stay alive long enough to see the result (e.g. a short sleep in demos).
- go worker() schedules worker concurrently.
- Channels coordinate goroutines in real apps.
- Demo sleeps are for learning โ production uses sync or channels.
package main
import (
"fmt"
"time"
)
func worker() {
fmt.Println("Worker active!")
}
func main() {
go worker()
time.Sleep(50 * time.Millisecond)
}
After you read this chapter, use Write (when available) and Quiz on this page to lock it in โ same flow as C, Python, and the other Learn languages.