WriteIntoWriter handles error values

This commit is contained in:
milarin 2023-03-25 11:52:57 +01:00
parent e9fdfd6e42
commit 9e62bab91e

View File

@ -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)
})
}