Created
July 12, 2019 10:36
-
-
Save blanchonvincent/f4f68306a60d57269337c5c90cff3835 to your computer and use it in GitHub Desktop.
Medium - buffered channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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