Skip to content

Instantly share code, notes, and snippets.

@phoorichet
Last active April 24, 2017 10:19
Show Gist options
  • Save phoorichet/371fa2d2ccc80d788f9fd7314f9e5ae1 to your computer and use it in GitHub Desktop.
Save phoorichet/371fa2d2ccc80d788f9fd7314f9e5ae1 to your computer and use it in GitHub Desktop.
func producer(total int) chan *http.Request {
queue := make(chan *http.Request)
// make sure that this the for-loop is run using goroutine
// otherwiser, it will block
go func() {
for i := 0; i < total; i++ {
// ignore error assuming that the request valid
req, _ := http.NewRequest("GET", "http://localhost:9000", nil)
queue <- req
}
// close the channel when then number of generated requests reaches total
close(queue)
}()
return queue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment