Skip to content

Instantly share code, notes, and snippets.

@Glyphack
Created March 11, 2023 15:22
Show Gist options
  • Save Glyphack/157dfabe23bc28d92f91a43ad551ce95 to your computer and use it in GitHub Desktop.
Save Glyphack/157dfabe23bc28d92f91a43ad551ce95 to your computer and use it in GitHub Desktop.
Golang: Wait group, channels, blocking operation
package main
import (
"fmt"
"sync"
)
func main() {
ch := make(chan int)
wg := sync.WaitGroup{}
go func() {
for i := range ch {
fmt.Println(i)
fmt.Println("call")
wg.Done()
}
fmt.Println("exit")
wg.Done()
}()
wg.Add(3)
ch <- 1
ch <- 2
close(ch)
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment