mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(package): [concurrency] stop Take when the source closes (#424)
* fix(package): [concurrency] stop Take when the source closes * test(package): [concurrency] cover Take with closed and idle source
This commit is contained in:
1 parent
b4302b2d15
commit
c403dd3a2a
2 files changed
+38
-1
No files matched your search
+10
-1
@@ -90,7 +90,16 @@ func (c *Channel[T]) Take(ctx context.Context, valueStream <-chan T, number int)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case takeStream <- <-valueStream:
|
||||
case v, ok := <-valueStream:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case takeStream <- v:
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in new issue
Block a user