mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-17 11:12:28 +08:00
fix: fix OrDone func
This commit is contained in:
@@ -222,24 +222,26 @@ func (c *Channel) Or(channels ...<-chan any) <-chan any {
|
|||||||
|
|
||||||
// OrDone
|
// OrDone
|
||||||
func (c *Channel) OrDone(ctx context.Context, channel <-chan any) <-chan any {
|
func (c *Channel) OrDone(ctx context.Context, channel <-chan any) <-chan any {
|
||||||
resStream := make(chan any)
|
valStream := make(chan any)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(resStream)
|
defer close(valStream)
|
||||||
|
for {
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
case v, ok := <-channel:
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
select {
|
select {
|
||||||
case resStream <- v:
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case v, ok := <-channel:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
select {
|
||||||
|
case valStream <- v:
|
||||||
|
case <-ctx.Done():
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return resStream
|
return valStream
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user