diff --git a/chan_io.go b/chan_io.go index c051655..fb59584 100644 --- a/chan_io.go +++ b/chan_io.go @@ -21,9 +21,8 @@ func WriteIntoDelayed[T any](ch chan<- T, delay time.Duration, values ...T) { // WriteIntoWriter reads all values from ch and writes them via fmt.Fprintln to all writers func WriteIntoWriter[T any](ch <-chan T, writers ...io.Writer) { - for value := range ch { - for _, w := range writers { - fmt.Fprintln(w, value) - } - } + w := io.MultiWriter(writers...) + Each(ch, func(value T) { + fmt.Fprintln(w, value) + }) } diff --git a/timeout.go b/timeout.go index d3bb1e8..203955e 100644 --- a/timeout.go +++ b/timeout.go @@ -3,7 +3,8 @@ package channel import "time" // CloseOnTimeout returns a channel which receives all values from the source. -// If no value was received in the given timeout duration, the returned channel will be closed +// If no value was received in the given timeout duration, the returned channel will be closed. +// The input channel will not be closed. func CloseOnTimeout[T any](source <-chan T, timeout time.Duration) <-chan T { output := make(chan T, cap(source))