From 55c3c7a46450b064d3a3e8a1db82fa446e3be95b Mon Sep 17 00:00:00 2001 From: Timon Ringwald Date: Wed, 30 Mar 2022 15:49:24 +0200 Subject: [PATCH] various optimizations --- chan_io.go | 9 ++++----- timeout.go | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) 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))