Skip to content

Instantly share code, notes, and snippets.

@inhzus inhzus/channel.go
Created Jul 11, 2019

Embed
What would you like to do?
Passing channel over channel to do request & get response
package main
import "fmt"
var queue = make(chan int)
var c = make(chan chan error)
func request() {
for i := 0; i < 4; i++ {
queue <- i
}
rsp := make(chan error)
c <- rsp
fmt.Printf("request: %v", <-rsp)
}
func response() {
for {
select {
case val := <-queue:
fmt.Printf("response: %v\n", val)
case rsp := <-c:
rsp <- fmt.Errorf("stop signal recieved")
return
}
}
}
func main() {
go response()
request()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.