mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-12 08:42:29 +08:00
feat: add func in channel.go
This commit is contained in:
@@ -3,6 +3,7 @@ package concurrency
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/duke-git/lancet/v2/internal"
|
||||
)
|
||||
@@ -108,3 +109,25 @@ func TestFanIn(t *testing.T) {
|
||||
|
||||
assert.Equal(1, 1)
|
||||
}
|
||||
|
||||
func TestOr(t *testing.T) {
|
||||
assert := internal.NewAssert(t, "TestOr")
|
||||
|
||||
sig := func(after time.Duration) <-chan any {
|
||||
c := make(chan interface{})
|
||||
go func() {
|
||||
defer close(c)
|
||||
time.Sleep(after)
|
||||
}()
|
||||
return c
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
||||
c := NewChannel()
|
||||
<-c.Or(sig(2*time.Hour), sig(5*time.Minute), sig(1*time.Second), sig(1*time.Hour), sig(1*time.Minute))
|
||||
|
||||
t.Logf("done after %v", time.Since(start))
|
||||
|
||||
assert.Equal(1, 1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user