channel/forward.go

12 lines
351 B
Go
Raw Normal View History

2022-02-09 12:10:02 +01:00
package channel
// Forward reads all values from all sources and sends them to target.
// It blocks until all values are forwarded and the out channel was closed.
// Use with go keyword for non-blocking behavior
func Forward[T any](target chan<- T, sources ...<-chan T) {
for value := range Merge(sources...) {
target <- value
}
close(target)
}