Files
wagslane 9be3074de6 first
2023-05-01 15:25:27 -06:00
..
2023-05-01 15:25:27 -06:00
2023-05-01 15:25:27 -06:00

Channels Review

Here are a few extra things you should understand about channels from Dave Cheney's awesome article.

A send to a nil channel blocks forever

var c chan string // c is nil
c <- "let's get started" // blocks

A receive from a nil channel blocks forever

var c chan string // c is nil
fmt.Println(<-c) // blocks

A send to a closed channel panics

var c = make(chan int, 100)
close(c)
c <- 1 // panic: send on closed channel

A receive from a closed channel returns the zero value immediately

var c = make(chan int, 100)
close(c)
fmt.Println(<-c) // 0