diff --git a/parallel.go b/parallel.go index 5aa7dc0a7c..ac57e56626 100644 --- a/parallel.go +++ b/parallel.go @@ -7,15 +7,13 @@ import ( ) const ( - MaxGenericWorkers = 8 + defaultWorkersCount = 8 ) -type GenericParallelErrors struct { - Errors []GenericContainerRequestError -} - -func (gpe GenericParallelErrors) Error() string { - return fmt.Sprintf("%v", gpe.Errors) +// GenericParallelOptions represents additional options for running +// * WorkersCount - count of parallel workers. if field empty(zero), default value will be 'defaultWorkersCount' +type GenericParallelOptions struct { + WorkersCount int } // GenericContainerRequestError represents error from parallel request @@ -24,6 +22,14 @@ type GenericContainerRequestError struct { Error error } +type GenericParallelErrors struct { + Errors []GenericContainerRequestError +} + +func (gpe GenericParallelErrors) Error() string { + return fmt.Sprintf("%v", gpe.Errors) +} + func genericContainerRunner( ctx context.Context, requests <-chan GenericContainerRequest, @@ -45,8 +51,12 @@ func genericContainerRunner( } // GenericParallelContainers creates a generic containers with parameters in parallel mode -func GenericParallelContainers(ctx context.Context, reqs []GenericContainerRequest) ([]Container, error) { - tasksChanSize := MaxGenericWorkers +func GenericParallelContainers(ctx context.Context, reqs []GenericContainerRequest, opt GenericParallelOptions) ([]Container, error) { + if opt.WorkersCount == 0 { + opt.WorkersCount = defaultWorkersCount + } + + tasksChanSize := opt.WorkersCount if tasksChanSize > len(reqs) { tasksChanSize = len(reqs) } diff --git a/parallel_test.go b/parallel_test.go index a070aff50c..1893d3dadb 100644 --- a/parallel_test.go +++ b/parallel_test.go @@ -69,7 +69,7 @@ func TestGenericParallelContainers(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - res, err := GenericParallelContainers(context.Background(), tc.reqs) + res, err := GenericParallelContainers(context.Background(), tc.reqs, GenericParallelOptions{}) if err != nil && tc.expErrors > 0 { e, _ := err.(GenericParallelErrors)