Skip to content

Instantly share code, notes, and snippets.

@blanchonvincent
Created July 12, 2019 10:36
Show Gist options
  • Save blanchonvincent/f4f68306a60d57269337c5c90cff3835 to your computer and use it in GitHub Desktop.
Save blanchonvincent/f4f68306a60d57269337c5c90cff3835 to your computer and use it in GitHub Desktop.
Medium - buffered channel
package main
import (
"sync"
"time"
)
func main() {
c := make(chan string, 2)
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
c <- `foo`
c <- `bar`
}()
go func() {
defer wg.Done()
time.Sleep(time.Second * 1)
println(`Message: `+ <-c)
println(`Message: `+ <-c)
}()
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment