github.com/qjfoidnh/BaiduPCS-Go@v0.0.0-20231011165705-caa18a3765f3/pcsutil/waitgroup/wait_group_test.go (about)

     1  package waitgroup
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  )
     8  
     9  func TestWg(t *testing.T) {
    10  	wg := NewWaitGroup(2)
    11  	for i := 0; i < 60; i++ {
    12  		wg.AddDelta()
    13  		go func(i int) {
    14  			fmt.Println(i, wg.Parallel())
    15  			time.Sleep(1e9)
    16  			wg.Done()
    17  		}(i)
    18  	}
    19  	wg.Wait()
    20  }