Tutorial
create a new goroutine
go f(x,y,z)
channels
Channels are a typed conduit through which you can send and receive values with the channel operator, <-
usually, will use channels to communicate between multiple threads
//create channel
ch := make(chan int,len)
//send & receive
ch <- v // Send v to channel ch.
v := <-ch // Receive from ch, and
// assign value to v.
By default, sends and receives block until the other side is ready. This allows goroutines to synchronize without explicit locks or condition variables.
if we overfill the buffer…
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan send]:
main.main()
/tmp/sandbox228860454/prog.go:8 +0x73
select
The select statement lets a goroutine wait on multiple communication operations.
A select blocks until one of its cases can run, then it executes that case. It chooses one at random if multiple are ready.
boom := time.After(500 * time.Millisecond)
for {
select {
case <-boom:
fmt.Println("BOOM!")
return
}