package main
func foo(input <-chan char, output chan<- string) {
for {
select {
case c, ok := <-input:
if ok { // ThereAreValuesBufferedIn(input)
... process c
} else { // input is closed
... handle closed input
}
default:
output <- "update message"
c, ok := <-input // will block
DoSomethingWith(c, ok)
}
}
}
EDIT: Fixed scoping bug.