Standard library / sync
sync.WaitGroup
Track outstanding tasks and wait for them to complete. Do not copy after first use. Expected stdout: '7\n'.
Formal Syntax & Structure
go syntaxgo
type WaitGroup struct {}Working Example
Example Snippetgo
package main
import ( "fmt" "sync")
func main() { var w sync.WaitGroup w.Add(1) done := make(chan int, 1) go func() { defer w.Done(); done <- 7 }() w.Wait() fmt.Println(<-done)}