1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-03-01 00:35: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
+7 -5
View File
@@ -222,11 +222,11 @@ 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 { select {
case <-ctx.Done(): case <-ctx.Done():
return return
@@ -235,11 +235,13 @@ func (c *Channel) OrDone(ctx context.Context, channel <-chan any) <-chan any {
return return
} }
select { select {
case resStream <- v: case valStream <- v:
case <-ctx.Done(): case <-ctx.Done():
} }
} }
}
}() }()
return resStream return valStream
} }