github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/app/bconcurrent/or_done_test.go (about)

     1  package bconcurrent
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func signal(d time.Duration) <-chan time.Duration {
     9  	c := make(chan time.Duration, 1)
    10  	go func() {
    11  		defer close(c)
    12  		time.Sleep(d)
    13  	}()
    14  	return c
    15  }
    16  
    17  func TestOrDone(t *testing.T) {
    18  	start := time.Now()
    19  	<-OrDone(
    20  		signal(10*time.Second),
    21  		signal(20*time.Second),
    22  		signal(30*time.Second),
    23  		signal(40*time.Second),
    24  		signal(50*time.Second),
    25  		signal(3*time.Second),
    26  	)
    27  	t.Log("done", time.Since(start))
    28  }