3 ms·
There are many ways to deal with this, here is a simple one: ... ch := make(chan int) defer close(ch) //I can timeout later if I want go consumer(ch)
by voidlogic 14y ago
There are many ways to deal with this, here is a simple one:
...
ch := make(chan int)
defer close(ch) //I can timeout later if I want
go consumer(ch)
...
//I timeout down here and return
}
func consumer(input chan int) { //I will terminate when the input channel is closed
for x := range input {
fmt.Printf("I got %d!\n", x)
}
}