From 9e62bab91e2cca90138c161262daf9073fea255f Mon Sep 17 00:00:00 2001 From: milarin Date: Sat, 25 Mar 2023 11:52:57 +0100 Subject: [PATCH] WriteIntoWriter handles error values --- chan_io.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chan_io.go b/chan_io.go index 3c9d41c..c3e048e 100644 --- a/chan_io.go +++ b/chan_io.go @@ -23,6 +23,10 @@ func WriteIntoDelayed[T any](ch chan<- T, delay time.Duration, values ...T) { func WriteIntoWriter[T any](ch <-chan T, writers ...io.Writer) { w := io.MultiWriter(writers...) EachSuccessive(ch, func(value T) { + if err, ok := any(value).(error); ok { + fmt.Fprintln(w, err.Error()) + return + } fmt.Fprintln(w, value) }) }