Skip to content

Instantly share code, notes, and snippets.

@horzu
Last active March 17, 2022 12:54
Show Gist options
  • Save horzu/17116e9e8510a2fe84925dd6d3f063cb to your computer and use it in GitHub Desktop.
Save horzu/17116e9e8510a2fe84925dd6d3f063cb to your computer and use it in GitHub Desktop.
Concurrency in Go: Go routines example - 2
package main
import (
"fmt"
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
wg.Add(1) // increments WaitGroup counter
go func(){
counter("first")
wg.Done() // decrements WaitGroup counter
}()
wg.Wait() // waits for the counter to be zero to continiou
}
func counter(rank string) {
for i := 1; i <= 7; i++ {
fmt.Println(i, rank)
time.Sleep(time.Second * 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment