Standard library / sync

sync.WaitGroup.Done()

Decrement the counter by one, usually deferred by a worker. Expected stdout: '7\n'.

Formal Syntax & Structure

go syntaxgo
func (wg *WaitGroup) Done()

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)}
Go Reference