fixed param ordering
This commit is contained in:
parent
6d79f07f5a
commit
07be46c4fe
11
timeout.go
11
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user