1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

fix: fix OrDone func

This commit is contained in:
dudaodong
2022-04-21 14:19:38 +08:00
parent c27ccad2b9
commit 9444582e44

View File

@@ -222,24 +222,26 @@ func (c *Channel) Or(channels ...<-chan any) <-chan any {
// OrDone
func (c *Channel) OrDone(ctx context.Context, channel <-chan any) <-chan any {
resStream := make(chan any)
valStream := make(chan any)
go func() {
defer close(resStream)
select {
case <-ctx.Done():
return
case v, ok := <-channel:
if !ok {
return
}
defer close(valStream)
for {
select {
case resStream <- v:
case <-ctx.Done():
return
case v, ok := <-channel:
if !ok {
return
}
select {
case valStream <- v:
case <-ctx.Done():
}
}
}
}()
return resStream
return valStream
}