どうすれば次のようなことができますか?:
func foo(input <-chan char, output chan<- string) {
var c char
var ok bool
for {
if ThereAreValuesBufferedIn(input) {
c, ok = <-input
} else {
output <- "update message"
c, ok = <-input
}
DoSomethingWith(c, ok)
}
}
基本的に、チャンにバッファリングされた値があるかどうかを確認して、ない場合は、スレッドがブロックされる前に更新メッセージを送信できるようにします。