Last active
August 29, 2015 14:20
-
-
Save Moddus/441235bca961f6059d8a to your computer and use it in GitHub Desktop.
Just some golang snipptes
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 ( | |
"log" | |
) | |
func main() { | |
c := make(chan string) | |
for i := 0; i < 10; i++ { | |
go func(i int, c chan string) { | |
log.Println(i) | |
c <- "" | |
}(i, c) | |
} | |
for i:= 0; i < 10; i++ { | |
<- c | |
} | |
} |
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 ( | |
"log" | |
"sync" | |
) | |
func main() { | |
var wg sync.WaitGroup | |
for i := 0; i < 10; i++ { | |
wg.Add(1) | |
go func(i int) { | |
defer wg.Done() | |
log.Println(i) | |
}(i) | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment