1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-15 18:22:27 +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

@@ -168,7 +168,8 @@ func ExampleChannel_Tee() {
func ExampleChannel_Bridge() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
m1 := make(map[int]int)
m2 := make(map[int]int)
c := NewChannel[int]()
genVals := func() <-chan <-chan int {
out := make(chan (<-chan int))
@@ -177,6 +178,7 @@ func ExampleChannel_Bridge() {
for i := 1; i <= 5; i++ {
stream := make(chan int, 1)
stream <- i
m1[i]++
close(stream)
out <- stream
}
@@ -185,12 +187,15 @@ func ExampleChannel_Bridge() {
}
for v := range c.Bridge(ctx, genVals()) {
fmt.Println(v)
m2[v]++
}
for k, v := range m1 {
fmt.Println(m2[k] == v)
}
// Output:
// 1
// 2
// 3
// 4
// 5
// true
// true
// true
// true
// true
}