I have the following minimal example that bails out after the first command line input due to deadlock:
package main
import "fmt"
import "os"
func main() {
channel1 := make(chan string)
go func() {
var str string
for {
fmt.Fscanln(os.Stdin, &str)
channel1 <- str
}
}()
for {
select {
case str := <-channel1:
fmt.Printf("Channel1 said: %v
", str)
}
}
}
I would have expected this to simply just take user input and echo it over and over again. Also, I did notice that if I add a second channel and a second go routine that it doesn't have any deadlock issues. So why does this deadlock?