Channels in Go

Intro A go maxim or proverb is: Do not communicate by sharing memory; instead, share memory by communicating. So what is a channel? A channel is a “typed” conduit (pipes) mechanism for goroutines to synchronize execution and communicate by passing values, using channel operator, <-. They are mechanism for communication between goroutines. Syntax // can only be used to send float64s chan<- float64 // can only be used to receive ints <-chan int // can be used to send and receive values of type Dosa chan Dosa (The data flows in the direction of the arrow. [Read More]

Goroutines - Go Coroutines

Syntax A goroutine is a lightweight thread managed by the Go runtime. go f(x, y, z) // notice go keyword starts a new goroutine running: f(x, y, z) The evaluation of f, x, y, and z happens in the current goroutine and the execution of f happens in the new goroutine. All goroutines in a single program share the same address space. So access to shared memory must be synchronized. The sync package provides useful primitives, although you won’t need them much in Go as there are other primitives. [Read More]