package main

import (
	"fmt"
	"sync"
	"time"
)

func worker(id int, wg *sync.WaitGroup) {
	defer wg.Done()
	fmt.Printf("worker-%d 开始工作\n", id)
	time.Sleep(time.Duration(id) * 300 * time.Millisecond)
	fmt.Printf("worker-%d 完成\n", id)
}

func main() {
	var wg sync.WaitGroup

	n := 3
	wg.Add(n)

	for i := 1; i <= n; i++ {
		go worker(i, &wg)
	}

	fmt.Println("main: 等待所有 worker 完成...")
	wg.Wait()
	fmt.Println("main: 全部完成")
}
