35 lines
576 B
Go
35 lines
576 B
Go
// SPDX-FileCopyrightText: 2021 The NGI Pointer Secure-Scuttlebutt Team of 2020/2021
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package testutils
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
// MergeErrorChans is a simple Fan-In for async errors
|
|
// TODO: should be replaced with x/sync/errgroup
|
|
func MergeErrorChans(cs ...<-chan error) <-chan error {
|
|
var wg sync.WaitGroup
|
|
out := make(chan error, 1)
|
|
|
|
output := func(c <-chan error) {
|
|
for a := range c {
|
|
out <- a
|
|
}
|
|
wg.Done()
|
|
}
|
|
|
|
wg.Add(len(cs))
|
|
for _, c := range cs {
|
|
go output(c)
|
|
}
|
|
|
|
go func() {
|
|
wg.Wait()
|
|
close(out)
|
|
}()
|
|
return out
|
|
}
|