Created
September 6, 2015 14:37
-
-
Save kennethzfeng/7ea387e3a3b5c7ca67c8 to your computer and use it in GitHub Desktop.
Golang Gotchas
This file contains hidden or 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" | |
| "sync" | |
| ) | |
| func main() { | |
| wg := &sync.WaitGroup{} | |
| for _, v := range []int{1, 4, 7} { | |
| v := v | |
| wg.Add(1) | |
| go func() { | |
| fmt.Println(v) | |
| wg.Done() | |
| }() | |
| } | |
| wg.Wait() | |
| } |
This file contains hidden or 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" | |
| "sync" | |
| ) | |
| func main() { | |
| wg := &sync.WaitGroup{} | |
| for _, v := range []int{1, 4, 7} { | |
| wg.Add(1) | |
| go func() { | |
| fmt.Println(v) | |
| wg.Done() | |
| }() | |
| } | |
| wg.Wait() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another
right.go: