fixed cancel call in FindFirstAndCancel

This commit is contained in:
milarin 2024-01-10 22:00:20 +01:00
parent 35264315fd
commit 6fcd709cd3

View File

@ -10,8 +10,8 @@ func FindFirst[T any](source <-chan T) *T {
} }
func FindFirstAndCancel[T any](source <-chan T, cancel context.CancelFunc) *T { func FindFirstAndCancel[T any](source <-chan T, cancel context.CancelFunc) *T {
defer cancel()
for v := range source { for v := range source {
cancel()
return &v return &v
} }
return nil return nil