1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-03-01 00:35:28 +08:00

make Bridge not block in the first stream that not closed (#288)

* not block in the first channel

* make Bridge not block in the first stream that not closed

* Bridge with test
This commit is contained in:
Tuuuuuuuuu
2025-01-14 16:19:45 +08:00
committed by GitHub
parent a0d97cf38e
commit e27df00fa8
3 changed files with 31 additions and 19 deletions

View File

@@ -169,7 +169,8 @@ func TestTee(t *testing.T) {
func TestBridge(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestBridge")
m1 := make(map[int]int)
m2 := make(map[int]int)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -181,6 +182,7 @@ func TestBridge(t *testing.T) {
for i := 0; i < 10; i++ {
stream := make(chan int, 1)
stream <- i
m1[i]++
close(stream)
chanStream <- stream
}
@@ -188,9 +190,11 @@ func TestBridge(t *testing.T) {
return chanStream
}
index := 0
for val := range c.Bridge(ctx, genVals()) {
assert.Equal(index, val)
index++
m2[val]++
}
for k, v := range m1 {
assert.Equal(m2[k], v)
}
}