I've been trying to use channels to build some kind of producer / consumer. I have a requests
channel where the many producers push requests, then I have processRequests
that handles the requests.
package main
var requests chan string
func processRequests() {
for {
request <- requests
// Process request...
// And return response - how?
}
}
func main() {
requests = make(chan string)
go processRequests()
requests <- "doSomething"
requests <- "doSomethingElse"
requests <- "etc"
select {} // Block forever
}
What I'm wondering is what would be the best way to send back a response to the producer (and to the right one, since there's more than one), once the request is fulfilled? Basically how to make this a two way channel?
Any idea how it could be done?