Receiving from a channel with <- chan or for range loop blocks.

Sometimes you want to limit time waiting for a value on a channel.

It’s possible with select:

https://codeeval.dev/gist/12ace93c5db6fa934ba022a212bbba47

Let's dig into how this works:

select {
	case res := <-chResult:
		fmt.Printf("Got %d from worker\\n", res)
	case <-time.After(100 * time.Millisecond):
		fmt.Printf("Timed out before worker finished\\n")
}