Single channel, single goroutine, one write, one read.
https://codeeval.dev/gist/014c3b0bba31bb1ca239ac5fbc77010e
The channel ch
is an unbuffered or synchronous channel.
The time.Sleep
is here to illustrate main()
function will wait on the ch
channel, which means the function literal executed as a goroutine has the time to send a value through that channel: the receive operator <-ch
will block the execution of main()
.
If it didn’t, the goroutine would be killed when main()
exits, and would not have time to send its value.