You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What do you about either expanding or writing a function similar to mapWithOutput to do the connect calls in parallel. Its basically a combination of connectNodes with mapWithOutput
func mapConnectWithOutput(from, to []int, nodes []testbedi.Core, timeout time.Duration) ([]Result, error) {
var wg sync.WaitGroup
var lk sync.Mutex
var results []Result
if err := validRange(to, len(nodes)); err != nil {
return results, err
}
if err := validRange(from, len(nodes)); err != nil {
return results, err
}
for _, f := range from {
for _, t := range to {
wg.Add(1)
go func(from, to int, nodeFrom, nodeTo testbedi.Core) {
defer wg.Done()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
err := nodeFrom.Connect(ctx, nodeTo)
lk.Lock()
defer lk.Unlock()
results = append(results, Result{
Node: from,
Output: nil,
Error: errors.Wrapf(err, "node[%d] => node[%d]", from, to),
})
}(f, t, nodes[f], nodes[t])
}
}
wg.Wait()
return results, nil
}
It definitely needs testing and polishing but I think it conveys the idea.
Another idea is to use the mapListWithOutput that is under development in PR #75
We can probably throw that code into connectNodes. Returning the results is fine as well, I just wouldn't call it mapConnectWithOutput as it's not really a map like function (apply a function over an input).
See: #61 (comment)
The text was updated successfully, but these errors were encountered: