Sobes.tech
Junior — Middle

Mis juhtub, kui proovite lugeda andmeid kanalilt, mis pole veel initsialiseeritud?

sobes.tech AI

Vastus AI-lt

If you try to read data from a channel in Go that has not been initialized (i.e., is nil), the read operation will block forever. This will cause the goroutine attempting to read from such a channel to hang, as the channel does not exist and cannot transmit data.

Example:

var ch chan int // ch is nil

func main() {
    fmt.Println(<-ch) // blocks forever
}

To avoid this, the channel should be initialized using make, for example: ch := make(chan int).