Skip to content

Instantly share code, notes, and snippets.

@ahndmal
Created May 31, 2022 15:26
Show Gist options
  • Save ahndmal/c862fedf0b3a3fab24726921954acee8 to your computer and use it in GitHub Desktop.
Save ahndmal/c862fedf0b3a3fab24726921954acee8 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
"time"
)
func worker(id int) {
fmt.Printf("Worker %d starting\n", id)
time.Sleep(time.Second)
fmt.Printf("Worker %d done\n", id)
}
func main() {
var wg sync.WaitGroup
for i := 1; i <= 5; i++ {
wg.Add(1)
i := i
go func() {
defer wg.Done()
worker(i)
}()
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment