Concurrency - gablesiak/learning-path GitHub Wiki

Goroutines

-functions or methods that run concurrently with other functions or methods.

-can be thought of as lightweight threads. Comparision: Goroutine vs thread

-cost of creating a Goroutine is tiny when compared to a thread.

How to run:

Prefix the function or method call with the keyword go

Channels

-can be thought of as pipes using which Goroutines communicate

-each channel has a type associated with it - type of data that the channel is allowed to transport

How to use:

a := make(chan int)

data := <- a // read from channel a

a <- data // write to channel a