Created
January 19, 2024 23:06
-
-
Save krashanoff/4c6ac02a3e62f79c490d8f381c7ddd47 to your computer and use it in GitHub Desktop.
Simple program to demonstrate Go's iterator aliasing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type A struct { | |
b int | |
} | |
func main() { | |
theAs := []A{} | |
for i := 0; i < 10; i++ { | |
theAs = append(theAs, A{b: i}) | |
} | |
fmt.Println(theAs) | |
done := make(chan bool, 10) | |
for _, a := range theAs { | |
go func() { | |
fmt.Println(a) | |
done <- true | |
}() | |
} | |
for i := 0; i < 10; i++ { | |
<-done | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment