Last active
April 24, 2017 10:19
-
-
Save phoorichet/371fa2d2ccc80d788f9fd7314f9e5ae1 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 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