Created
February 19, 2017 13:51
-
-
Save maniankara/e46060bb13b1e03607d3888843e64f10 to your computer and use it in GitHub Desktop.
Executing go routines inside for loop with Boolean channels
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 fragments | |
func downloadUrls(urls []string) { | |
done := make(chan bool, len(urls)) | |
for _, url := range urls { | |
go func(url string) { | |
// perform download here | |
done <- true | |
}(url) | |
} | |
// ensure all the routines are done | |
for i:=0; i<len(urls); i++ { <- done } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment