From 07be46c4fe83793a1c5fc9bd6e7b721c2447e2dd Mon Sep 17 00:00:00 2001 From: Tordarus Date: Wed, 9 Feb 2022 12:23:31 +0100 Subject: [PATCH] fixed param ordering --- timeout.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 }