package main
import (
"fmt"
"sync"
)
func main() {
var wg sync.WaitGroup
// Step 1: Add a counter to the WaitGroup
wg.Add(2)
// Step 2: Launch goroutines that will be waited for
go func() {
// Step 3: Defer the decrement of the counter when the goroutine completes
defer wg.Done()
// Step 4: Perform the task for the first goroutine
fmt.Println("Goroutine 1")
}()
go func() {
// Step 5: Defer the decrement of the counter when the goroutine completes
defer wg.Done()
// Step 6: Perform the task for the second goroutine
fmt.Println("Goroutine 2")
}()
// Step 7: Block and wait until the counter becomes zero
wg.Wait()
// Step 8: All goroutines have completed
fmt.Println("All Goroutines Completed")
}