MCPcopy
hub / github.com/wal-g/wal-g / runParallel

Function runParallel

internal/databases/sqlserver/sqlserver.go:406–430  ·  view source on GitHub ↗
(f func(int) error, cnt int, concurrency int)

Source from the content-addressed store, hash-verified

404}
405
406func runParallel(f func(int) error, cnt int, concurrency int) error {
407 if concurrency <= 0 {
408 concurrency = cnt
409 }
410 sem := make(chan struct{}, concurrency)
411 errs := make(chan error, cnt)
412 for i := 0; i < cnt; i++ {
413 go func(i int) {
414 sem <- struct{}{}
415 defer func() { <-sem }()
416 errs <- f(i)
417 }(i)
418 }
419 var errStr string
420 for i := 0; i < cnt; i++ {
421 err := <-errs
422 if err != nil {
423 errStr += err.Error() + "\n"
424 }
425 }
426 if errStr != "" {
427 return errors.New(errStr)
428 }
429 return nil
430}
431
432func getDBConcurrency() int {
433 concurrency, err := conf.GetMaxConcurrency(conf.SQLServerDBConcurrency)

Callers 6

HandleLogPushFunction · 0.85
HandleBackupRestoreFunction · 0.85
HandleBackupImportFunction · 0.85
HandleBackupExportFunction · 0.85
HandleBackupPushFunction · 0.85
HandleLogRestoreFunction · 0.85

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected