Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 861 Bytes

concurrency.md

File metadata and controls

29 lines (23 loc) · 861 Bytes

Concurrency

Tour

  1. Goroutines invoked by go f()

  2. Channels ch := make(chan int) Now you can ch <- 123 and <-ch.

  3. Can give an argument to decide how much to buffer

  4. Can close(ch) when done. Then someone else can range over it. Only needed if someone is ranging; otherwise it's unnecessary to close. You can check if val, ok := <-ch if needed

  5. select:

    select { case c <- 123: fmt.Println("Sent value!") case <-quit: fmt.Println("Someone sent us a value to quit!") }

  6. You can use a default case to be non-blocking.

  7. They show us how to use sync.Mutex which is simple.