process load balancing: broken but in progress

This commit is contained in:
Julien Neuhart
2019-09-19 17:28:29 +02:00
parent c5429f7efa
commit 171f93662f
33 changed files with 1681 additions and 117 deletions

View File

@@ -0,0 +1,6 @@
/*
Package xerrgroup helps running
many functions simultaneously and wait until
execution has completed or an error is encountered.
*/
package xerrgroup

View File

@@ -0,0 +1,20 @@
package xerrgroup
import (
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
"golang.org/x/sync/errgroup"
)
// Run runs all functions simultaneously and wait until
// execution has completed or an error is encountered.
func Run(fn ...func() error) error {
const op string = "xerrgroup.Run"
eg := errgroup.Group{}
for _, f := range fn {
eg.Go(f)
}
if err := eg.Wait(); err != nil {
return xerror.New(op, err)
}
return nil
}