diff --git a/timeout.go b/timeout.go index 806037a..d3bb1e8 100644 --- a/timeout.go +++ b/timeout.go @@ -2,11 +2,10 @@ package channel import "time" -// CloseOnTimeout returns a channel which receives all values from all sources in order of arrival. -// If no source is sending a value in the given timeout duration, the channel will be closed -func CloseOnTimeout[T any](timeout time.Duration, sources ...<-chan T) <-chan T { - input := Merge(sources...) - output := make(chan T, cap(input)) +// 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 +func CloseOnTimeout[T any](source <-chan T, timeout time.Duration) <-chan T { + output := make(chan T, cap(source)) go func() { defer close(output) @@ -15,7 +14,7 @@ func CloseOnTimeout[T any](timeout time.Duration, sources ...<-chan T) <-chan T timer := time.NewTimer(timeout) select { - case value, ok := <-input: + case value, ok := <-source: if !ok { return }