Standard library / sync
sync.WaitGroup.Wait()
Block until the counter is zero. A reused WaitGroup must have completed previous Wait calls before starting a new batch. Expected stdout: '7\n'.
Formal Syntax & Structure
go syntaxgo
func (wg *WaitGroup) Wait()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)}