(f func(int) error, cnt int, concurrency int)
| 404 | } |
| 405 | |
| 406 | func 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 | |
| 432 | func getDBConcurrency() int { |
| 433 | concurrency, err := conf.GetMaxConcurrency(conf.SQLServerDBConcurrency) |
no test coverage detected