various optimizations

This commit is contained in:
Timon Ringwald 2022-03-30 15:49:24 +02:00
parent 220f4e6525
commit 55c3c7a464
2 changed files with 6 additions and 6 deletions

View File

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

View File

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