Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/abci #188

Merged
merged 12 commits into from
Aug 21, 2023
27 changes: 6 additions & 21 deletions internal/app/kwild/server/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"net"
"path/filepath"
"sync"
"time"

// kwil-db
Expand Down Expand Up @@ -136,28 +135,14 @@ func (c *closeFuncs) addCloser(f func() error) {
c.closers = append(c.closers, f)
}

// closeAll concurrently closes all closers
// closeAll closeps all closers, in the order they were added
jchappelow marked this conversation as resolved.
Show resolved Hide resolved
func (c *closeFuncs) closeAll() error {
errs := make([]error, 0)
errCh := make(chan error, len(c.closers))
wg := sync.WaitGroup{}

for _, f := range c.closers {
wg.Add(1)
go func(f func() error) {
err := f()
if err != nil {
errCh <- err
}
wg.Done()
}(f)
}

wg.Wait()
close(errCh)

for err := range errCh {
errs = append(errs, err)
for _, closer := range c.closers {
err := closer()
if err != nil {
errs = append(errs, err)
}
}

return errors.Join(errs...)
Expand Down