Table of Contents

Goroutine

What is it?

A goroutine is a lightweight thread managed by the Go runtime. You start it with the `go` keyword.

What is it used for?

Example

package main
 
import (
    "fmt"
    "time"
)
 
func work(name string) {
    fmt.Println("start:", name)
    time.Sleep(200 * time.Millisecond)
    fmt.Println("done:", name)
}
 
func main() {
    go work("A")
    go work("B")
    time.Sleep(500 * time.Millisecond) // demo: wait a bit
}

Important notes

Hard words (English)