-
-
Save mjs/38a2c7cba406792a7143 to your computer and use it in GitHub Desktop.
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
func Download(out chan string, urls... string) { | |
for url := range(urls) { | |
go func() { | |
out <- HttpGet(url) | |
}() | |
} | |
} | |
func Process(in chan string) { | |
select { | |
case html := <- in: | |
// Do something with html | |
case <- time.After(10 * time.Second): | |
// Timed out! | |
} | |
} | |
func DoStuff() { | |
// Make a channel | |
pipe := make(chan string, 10) | |
// Kick off goroutines to download the URLs | |
Download(pipe, "http://blog.darkhax.com/2011/05/06/simple-ruby-pipes", "http://blog.darkhax.com/2011/03/28/rubber-duck-debugging") | |
// Process them, with a timeout | |
Process(pipe) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment