Last active
July 12, 2019 10:02
-
-
Save blanchonvincent/e3347fca2f581b6558c47f11b34a433b to your computer and use it in GitHub Desktop.
Medium - channel unbuffered 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) | |
var wg sync.WaitGroup | |
wg.Add(2) | |
go func() { | |
defer wg.Done() | |
c <- `foo` | |
}() | |
go func() { | |
defer wg.Done() | |
time.Sleep(time.Second * 1) | |
println(`Message: `+ <-c) | |
}() | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment