diff --git a/of.go b/of.go index da5a7cd..11959fb 100644 --- a/of.go +++ b/of.go @@ -59,7 +59,7 @@ func OfFunc[T any](ctx context.Context, buffer int, f func() T) <-chan T { func OfMap[K comparable, V, T any](m map[K]V, unmapper func(K, V) T) <-chan T { out := make(chan T, len(m)) - defer func() { + go func() { defer close(out) for k, v := range m { out <- unmapper(k, v) @@ -73,7 +73,7 @@ func OfMap[K comparable, V, T any](m map[K]V, unmapper func(K, V) T) <-chan T { func OfSeq[T any](seq iter.Seq[T]) <-chan T { out := make(chan T, 10) - defer func() { + go func() { defer close(out) for v := range seq { out <- v @@ -88,7 +88,7 @@ func OfSeq[T any](seq iter.Seq[T]) <-chan T { func OfSeq2[K comparable, V, T any](seq iter.Seq2[K, V], unmapper func(K, V) T) <-chan T { out := make(chan T, 10) - defer func() { + go func() { defer close(out) for key, value := range seq { out <- unmapper(key, value)