Working with unbuffered channels
By default, channels are unbuffered in V unless you specify the capacity. In this section, we will learn how to work with unbuffered channels. The main aspect of working with unbuffered channels is that the push operations on them block code from executing, so long as no coroutine pops the value out of the unbuffered channel.
Understanding the blocking nature of unbuffered channels
In this section, we will learn why unbuffered channels are blocking in nature. Consider the following code, which demonstrates the blocking behavior of the unbuffered channel:
module main fn main() { ch := chan int{} defer { ch.close() } ch <- 3 x := <-ch println(x) println('End main') }
In the preceding code, we have the main
function...