Skip to content

Go Memes

HOA PHAN edited this page Feb 28, 2024 · 8 revisions
//https://go.dev/blog/loopvar-preview
// docker run --rm -v "$(pwd)":/go/src/app -w /go/src/app golang:1.21   go run l.go
// docker run --rm -v "$(pwd)":/go/src/app -w /go/src/app golang:1.22.0 go run l.go
func main() {
    done := make(chan bool)

    values := []string{"a", "b", "c"}
    for _, v := range values {
        go func() {
            fmt.Println(v) // all 'c'
            done <- true
        }()
    }
    for _ = range values {
        <-done
    }
}
Screenshot 2023-10-21 at 6 49 18 am

eye

Clone this wiki locally