go
, chan
, and select
:go
creates a new goroutine, which means fetchUrl
will be executed within a new concurrent goroutine each time.chan
is the type representing a channel. Channels help us communicate among goroutines (main
being a goroutine itself as well).select .. case
is a switch .. case
dedicated to receiving messages sent through channels. Program stays here as long as all goroutines have not sent a message (either to say that url fetching is done, or to say that url fetching failed).main
goroutine can perfectly end while some goroutines are still working. This is possible because main
does not block other goroutines when it stops. But in real life it is almost always necessary to use channels in order to make our goroutines talk to each other.type interfaceName interface{}
var i interface{}
{Chirpir}
.