github.com/songzhibin97/gkit@v1.2.13/concurrent/or_done_test.go (about) 1 package concurrent 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func signal(d time.Duration) <-chan interface{} { 9 c := make(chan interface{}, 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 }